Skip to content

Commit

Permalink
Throw error if unicode is in reserved space - fixes dotnet#338
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Apr 1, 2015
1 parent 049d871 commit e7d64ae
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ lexIndentOffForML,"Consider using a file with extension '.ml' or '.mli' instead"
1242,parsMissingGreaterThan,"Unmatched '<'. Expected closing '>'"
1243,parsUnexpectedQuotationOperatorInTypeAliasDidYouMeanVerbatimString,"Unexpected quotation operator '<@' in type definition. If you intend to pass a verbatim string as a static argument to a type provider, put a space between the '<' and '@' characters."
1244,parsErrorParsingAsOperatorName,"Attempted to parse this as an operator name, but failed"
1245,lexInvalidUnicodeLiteral,"This is not a valid UTF-16 literal"
# Fsc.exe resource strings
fscTooManyErrors,"Exiting - too many errors"
2001,docfileNoXmlSuffix,"The documentation file has no .xml suffix"
Expand Down
8 changes: 6 additions & 2 deletions src/fsharp/lex.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,12 @@ and string sargs skip = parse

| unicodeGraphShort
{ let (buf,_fin,m,args) = sargs
addUnicodeChar buf (int (unicodeGraphShort (lexemeTrimLeft lexbuf 2)));
if not skip then (STRING_TEXT (LexCont.String(!args.ifdefStack,m))) else string sargs skip lexbuf }
let c = int (unicodeGraphShort (lexemeTrimLeft lexbuf 2))
if c >= 0xD800 && c <= 0xDFFF then
fail args lexbuf (FSComp.SR.lexInvalidUnicodeLiteral()) (CHAR (char c))
else
addUnicodeChar buf c;
if not skip then (STRING_TEXT (LexCont.String(!args.ifdefStack,m))) else string sargs skip lexbuf }

| unicodeGraphLong
{ let (buf,_fin,m,args) = sargs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// #Regression #Conformance #LexicalAnalysis
#light

// Verify error when trying to access U+D800 in string

//<Expects id="FS1245" status="error">This is not a valid UTF-16 literal</Expects>

let _ = '\uD7FF' // Ok
let _ = "\uE000" // Ok

let _ = "\uD800"

exit 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// #Regression #Conformance #LexicalAnalysis
#light

// Verify error when trying to access U+DFFF in string

//<Expects id="FS1245" status="error">This is not a valid UTF-16 literal</Expects>

let _ = "\uDFFF"

exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

SOURCE=E_ByteStrUnicodeChar01.fs # E_ByteStrUnicodeChar01.fs
SOURCE=E_ByteCharUnicodeChar01.fs # E_ByteCharUnicodeChar01.fs
SOURCE=E_InvalidUnicodeChar01.fs # E_InvalidUnicodeChar01.fs
SOURCE=E_InvalidUnicodeChar02.fs # E_InvalidUnicodeChar02.fs

SOURCE=E_MalformedShortUnicode01.fs SCFLAGS="--test:ErrorRanges" # E_MalformedShortUnicode01.fs
SOURCE=UnicodeString03.fs # UnicodeString03.fs
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharpqa/Source/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Conformance05 Conformance\LexicalAnalysis\LineDirectives
Conformance05 Conformance\LexicalAnalysis\NumericLiterals
Conformance05 Conformance\LexicalAnalysis\Shift\Generics

Conformance06 Conformance\LexicalAnalysis\StringsAndCharacters
Conformance06,Smoke Conformance\LexicalAnalysis\StringsAndCharacters
Conformance06 Conformance\LexicalAnalysis\SymbolicKeywords
Conformance06 Conformance\LexicalAnalysis\SymbolicOperators
Conformance06 Conformance\LexicalAnalysis\Whitespace
Expand Down

0 comments on commit e7d64ae

Please sign in to comment.