Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions gulp-html-partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ module.exports = (function () {
* @returns {String}
*/
function replaceAttributes(file, attributes) {
return (attributes || []).reduce((html, attrObj) =>
html.replace(options.variablePrefix + attrObj.key, attrObj.value), file && file.toString() || '');
let html = file && file.toString() || '';
(attributes || []).forEach((attrib) => {
let regex = new RegExp(escapeRegExp(options.variablePrefix + attrib.key), 'g');
html = html.replace(regex, attrib.value);
});
return html;
}

/**
Expand Down Expand Up @@ -159,4 +163,14 @@ module.exports = (function () {
}

return transform;

/**
* Escapes characters for use in a regular expression
* @param {string} s String to escape
* @returns {string}
* @source https://stackoverflow.com/a/3561711/1267001
*/
function escapeRegExp(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
})();