diff --git a/src/js/1p-filters.js b/src/js/1p-filters.js index c4f7590df..7e20a30c2 100644 --- a/src/js/1p-filters.js +++ b/src/js/1p-filters.js @@ -111,12 +111,12 @@ function currentStateChanged() { } function getEditorText() { - const text = cmEditor.getValue().replace(/\s+$/, ''); + const text = cmEditor.getValue().trimEnd(); return text === '' ? text : `${text}\n`; } function setEditorText(text) { - cmEditor.setValue(text.replace(/\s+$/, '') + '\n\n'); + cmEditor.setValue(`${text.trimEnd()}\n\n`); } /******************************************************************************/ diff --git a/src/js/arglist-parser.js b/src/js/arglist-parser.js index d8200df58..708029e2d 100644 --- a/src/js/arglist-parser.js +++ b/src/js/arglist-parser.js @@ -32,7 +32,7 @@ export class ArglistParser { this.transform = false; this.failed = false; this.reWhitespaceStart = /^\s+/; - this.reWhitespaceEnd = /\s+$/; + this.reWhitespaceEnd = /(?:^|\S)(\s+)$/; this.reOddTrailingEscape = /(?:^|[^\\])(?:\\\\)*\\$/; this.reTrailingEscapeChars = /\\+$/; } @@ -90,7 +90,7 @@ export class ArglistParser { } rightWhitespaceCount(s) { const match = this.reWhitespaceEnd.exec(s); - return match === null ? 0 : match[0].length; + return match === null ? 0 : match[1].length; } indexOfNextArgSeparator(pattern, separatorCode) { this.argBeg = this.argEnd = separatorCode !== this.separatorCode diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 66d2853ae..a3f6e1cc5 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -785,7 +785,7 @@ export class AstFilterParser { this.selectorCompiler = new ExtSelectorCompiler(options); // Regexes this.reWhitespaceStart = /^\s+/; - this.reWhitespaceEnd = /\s+$/; + this.reWhitespaceEnd = /(?:^|\S)(\s+)$/; this.reCommentLine = /^(?:!|#\s|####|\[adblock)/i; this.reExtAnchor = /(#@?(?:\$\?|\$|%|\?)?#).{1,2}/; this.reInlineComment = /(?:\s+#).*?$/; @@ -2786,7 +2786,7 @@ export class AstFilterParser { rightWhitespaceCount(s) { const match = this.reWhitespaceEnd.exec(s); - return match === null ? 0 : match[0].length; + return match === null ? 0 : match[1].length; } nextCommaInCommaSeparatedListString(s, start) { diff --git a/src/js/whitelist.js b/src/js/whitelist.js index 6d9e951c1..371d25f99 100644 --- a/src/js/whitelist.js +++ b/src/js/whitelist.js @@ -99,12 +99,12 @@ uBlockDashboard.patchCodeMirrorEditor(cmEditor); /******************************************************************************/ function getEditorText() { - let text = cmEditor.getValue().replace(/\s+$/, ''); - return text === '' ? text : text + '\n'; + const text = cmEditor.getValue().trimEnd(); + return text === '' ? text : `${text}\n`; } function setEditorText(text) { - cmEditor.setValue(text.replace(/\s+$/, '') + '\n'); + cmEditor.setValue(`${text.trimEnd()}\n`); } /******************************************************************************/