Avoid pairing null bytes characters

This commit is contained in:
Antonio Scandurra
2015-09-03 19:54:55 +02:00
parent daa38b2f44
commit ac64245848
2 changed files with 8 additions and 0 deletions

View File

@@ -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

View File

@@ -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