From ac64245848fc144e47406c156d520327f095c4a2 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 3 Sep 2015 19:54:55 +0200 Subject: [PATCH] Avoid pairing null bytes characters --- spec/text-utils-spec.coffee | 6 ++++++ src/text-utils.coffee | 2 ++ 2 files changed, 8 insertions(+) diff --git a/spec/text-utils-spec.coffee b/spec/text-utils-spec.coffee index 6a03bb02f..f5c2c87f9 100644 --- a/spec/text-utils-spec.coffee +++ b/spec/text-utils-spec.coffee @@ -17,6 +17,9 @@ describe 'text utilities', -> expect(textUtils.hasPairedCharacter('\uFE0E\uFE0E')).toBe false expect(textUtils.hasPairedCharacter('\u0301\u0301')).toBe false + expect(textUtils.hasPairedCharacter('\0\u0301')).toBe false + expect(textUtils.hasPairedCharacter('\0\uFE0E')).toBe false + describe '.isPairedCharacter(string, index)', -> it 'returns true when the index is the start of a high/low surrogate pair, variation sequence, or combined character', -> expect(textUtils.isPairedCharacter('a\uD835\uDF97b\uD835\uDF97c', 0)).toBe false @@ -44,3 +47,6 @@ describe 'text utilities', -> expect(textUtils.isPairedCharacter('ae\u0301c', 2)).toBe false expect(textUtils.isPairedCharacter('ae\u0301c', 3)).toBe false expect(textUtils.isPairedCharacter('ae\u0301c', 4)).toBe false + + expect(textUtils.isPairedCharacter('\0\u0301c', 0)).toBe false + expect(textUtils.isPairedCharacter('\0\uFE0E', 0)).toBe false diff --git a/src/text-utils.coffee b/src/text-utils.coffee index 37955dcd6..ec3ca0c29 100644 --- a/src/text-utils.coffee +++ b/src/text-utils.coffee @@ -30,6 +30,7 @@ isSurrogatePair = (charCodeA, charCodeB) -> # # Return a {Boolean}. isVariationSequence = (charCodeA, charCodeB) -> + return false if charCodeA is 0 not isVariationSelector(charCodeA) and isVariationSelector(charCodeB) # Are the given character codes a combined character pair? @@ -39,6 +40,7 @@ isVariationSequence = (charCodeA, charCodeB) -> # # Return a {Boolean}. isCombinedCharacter = (charCodeA, charCodeB) -> + return false if charCodeA is 0 not isCombiningCharacter(charCodeA) and isCombiningCharacter(charCodeB) # Is the character at the given index the start of high/low surrogate pair