🌐 AI搜索 & 代理 主页
Skip to content

Commit 2707070

Browse files
authored
fix: remove string.repeat for ie11 (#1772)
1 parent 7183d4f commit 2707070

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/Lexer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Tokenizer = require('./Tokenizer.js');
22
const { defaults } = require('./defaults.js');
33
const { block, inline } = require('./rules.js');
4+
const { repeatString } = require('./helpers.js');
45

56
/**
67
* smartypants text replacement
@@ -340,14 +341,14 @@ module.exports = class Lexer {
340341
if (links.length > 0) {
341342
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
342343
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
343-
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
344+
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
344345
}
345346
}
346347
}
347348
}
348349
// Mask out other blocks
349350
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
350-
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
351+
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
351352
}
352353

353354
while (src) {

src/helpers.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ function checkSanitizeDeprecation(opt) {
228228
}
229229
}
230230

231+
// copied from https://stackoverflow.com/a/5450113/806777
232+
function repeatString(pattern, count) {
233+
if (count < 1) {
234+
return '';
235+
}
236+
let result = '';
237+
while (count > 1) {
238+
if (count & 1) {
239+
result += pattern;
240+
}
241+
count >>= 1;
242+
pattern += pattern;
243+
}
244+
return result + pattern;
245+
}
246+
231247
module.exports = {
232248
escape,
233249
unescape,
@@ -239,5 +255,6 @@ module.exports = {
239255
splitCells,
240256
rtrim,
241257
findClosingBracket,
242-
checkSanitizeDeprecation
258+
checkSanitizeDeprecation,
259+
repeatString
243260
};

0 commit comments

Comments
 (0)