Skip to content

Commit

Permalink
fix: remove string.repeat for ie11 (#1772)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Oct 21, 2020
1 parent 7183d4f commit 2707070
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Lexer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Tokenizer = require('./Tokenizer.js');
const { defaults } = require('./defaults.js');
const { block, inline } = require('./rules.js');
const { repeatString } = require('./helpers.js');

/**
* smartypants text replacement
Expand Down Expand Up @@ -340,14 +341,14 @@ module.exports = class Lexer {
if (links.length > 0) {
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
}
}
}
}
// Mask out other blocks
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
}

while (src) {
Expand Down
19 changes: 18 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ function checkSanitizeDeprecation(opt) {
}
}

// copied from https://stackoverflow.com/a/5450113/806777
function repeatString(pattern, count) {
if (count < 1) {
return '';
}
let result = '';
while (count > 1) {
if (count & 1) {
result += pattern;
}
count >>= 1;
pattern += pattern;
}
return result + pattern;
}

module.exports = {
escape,
unescape,
Expand All @@ -239,5 +255,6 @@ module.exports = {
splitCells,
rtrim,
findClosingBracket,
checkSanitizeDeprecation
checkSanitizeDeprecation,
repeatString
};

1 comment on commit 2707070

@vercel
Copy link

@vercel vercel bot commented on 2707070 Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.