From 6633e2635d4600a0b82a68928f5bd0823b05517f Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 5 Jun 2020 09:57:48 -0400 Subject: [PATCH] Fix dealing with trailing newline characters Regression from: - https://github.com/gorhill/uBlock/commit/01b1ed9a982965378d732ab0cb4bcd68727fe910 The new parser needs to be able to deal with trailing newline characters, which if present will be interpreted as trailing spaces. --- src/js/static-filtering-parser.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index bb65f3b69..3b92676f5 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1000,10 +1000,17 @@ const BITHostname = BITNum | BITAlpha | BITUppercase | BITDash | BITPeriod const BITPatternToken = BITNum | BITAlpha | BITPercent; const BITLineComment = BITExclamation | BITHash | BITSquareBracket; +// Important: it is expected that lines passed to the parser have been +// trimmed of new line characters. Given this, any newline characters found +// will be interpreted as normal white spaces. + const charDescBits = [ /* 0x00 - 0x08 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 0x09 */ BITSpace, - /* 0x0A - 0x0F */ 0, 0, 0, 0, 0, 0, + /* 0x09 */ BITSpace, // \t + /* 0x0A */ BITSpace, // \n + /* 0x0B - 0x0C */ 0, 0, + /* 0x0D */ BITSpace, // \r + /* 0x0E - 0x0F */ 0, 0, /* 0x10 - 0x1F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */ BITSpace, /* 0x21 ! */ BITExclamation,