File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -597,21 +597,28 @@ parsers embedded = Parsers {..}
597
597
598
598
let toNumber = Data.List. foldl' (\ x y -> x * 16 + y) 0
599
599
600
- let fourCharacterEscapeSequence =
601
- fmap toNumber (Control.Monad. replicateM 4 hexNumber)
600
+ let fourCharacterEscapeSequence = do
601
+ ns <- Control.Monad. replicateM 4 hexNumber
602
+
603
+ let number = toNumber ns
604
+
605
+ Control.Monad. guard (validCodepoint number)
606
+ <|> fail " Invalid Unicode code point"
607
+
608
+ return number
602
609
603
610
let bracedEscapeSequence = do
604
611
_ <- char ' {'
605
612
ns <- some hexNumber
606
613
607
614
let number = toNumber ns
608
615
609
- Control.Monad. guard (number <= 0x10FFFF && validCodepoint ( Char. chr number) )
616
+ Control.Monad. guard (number <= 0x10FFFD && validCodepoint number)
610
617
<|> fail " Invalid Unicode code point"
611
618
612
619
_ <- char ' }'
613
620
614
- return (toNumber ns)
621
+ return number
615
622
616
623
n <- bracedEscapeSequence <|> fourCharacterEscapeSequence
617
624
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ module Dhall.Parser.Token (
110
110
import Dhall.Parser.Combinators
111
111
112
112
import Control.Applicative (Alternative (.. ), optional )
113
+ import Data.Bits ((.&.) )
113
114
import Data.Functor (void )
114
115
import Data.Semigroup (Semigroup (.. ))
115
116
import Data.Text (Text )
@@ -135,12 +136,14 @@ import Prelude hiding (const, pi)
135
136
136
137
import qualified Text.Parser.Token
137
138
138
- -- | Returns `True` if the given `Char ` is a valid Unicode codepoint
139
- validCodepoint :: Char -> Bool
139
+ -- | Returns `True` if the given `Int ` is a valid Unicode codepoint
140
+ validCodepoint :: Int -> Bool
140
141
validCodepoint c =
141
- not (category == Char. Surrogate || category == Char. NotAssigned )
142
+ not (category == Char. Surrogate
143
+ || c .&. 0xFFFE == 0xFFFE
144
+ || c .&. 0xFFFF == 0xFFFF )
142
145
where
143
- category = Char. generalCategory c
146
+ category = Char. generalCategory ( Char. chr c)
144
147
145
148
{-| Parse 0 or more whitespace characters (including comments)
146
149
You can’t perform that action at this time.
0 commit comments