@@ -1229,7 +1229,7 @@ fn escaped_char(input: &mut Input<'_>) -> PResult<char> {
12291229 ) ) ,
12301230 (
12311231 "u{" ,
1232- cut_err ( take_while ( 1 ..6 , AsChar :: is_hex_digit) ) ,
1232+ cut_err ( take_while ( 1 ..= 6 , AsChar :: is_hex_digit) ) ,
12331233 cut_err ( "}" ) ,
12341234 )
12351235 . context ( cx ( ) . lbl ( "unicode escape char" ) )
@@ -1250,6 +1250,7 @@ fn escaped_char(input: &mut Input<'_>) -> PResult<char> {
12501250/// multi-line-raw-string-body := (unicode - disallowed-literal-code-points)*?
12511251/// ```
12521252fn raw_string ( input : & mut Input < ' _ > ) -> PResult < KdlValue > {
1253+ let _start_loc = input. location ( ) ;
12531254 let hashes: String = repeat ( 1 .., "#" ) . parse_next ( input) ?;
12541255 let quotes = alt ( ( ( "\" \" \" " , newline) . take ( ) , "\" " ) ) . parse_next ( input) ?;
12551256 let is_multiline = quotes. len ( ) > 1 ;
@@ -1343,7 +1344,17 @@ fn raw_string(input: &mut Input<'_>) -> PResult<KdlValue> {
13431344 "\" " . context ( cx ( ) . lbl ( "raw string closing quotes" ) )
13441345 } ;
13451346 cut_err ( ( closing_quotes, & hashes[ ..] ) ) . parse_next ( input) ?;
1346- Ok ( KdlValue :: String ( body) )
1347+ if body == "\" " {
1348+ Err ( ErrMode :: Cut ( KdlParseError {
1349+ message : Some ( "Single-line raw strings cannot look like multi-line ones" . into ( ) ) ,
1350+ span : Some ( ( _start_loc..input. location ( ) ) . into ( ) ) ,
1351+ label : Some ( "triple quotes" . into ( ) ) ,
1352+ help : Some ( "Consider using a regular escaped string if all you want is a single quote: \" \\ \" \" " . into ( ) ) ,
1353+ severity : Some ( Severity :: Error ) ,
1354+ } ) )
1355+ } else {
1356+ Ok ( KdlValue :: String ( body) )
1357+ }
13471358}
13481359
13491360/// Like badval, but is able to slurp up invalid raw strings, which contain whitespace.
@@ -1383,6 +1394,10 @@ mod string_tests {
13831394 string. parse( new_input( "\" foo\\ u{0a}\" " ) ) . unwrap( ) ,
13841395 Some ( KdlValue :: String ( "foo\u{0a} " . into( ) ) )
13851396 ) ;
1397+ assert_eq ! (
1398+ string. parse( new_input( "\" \\ u{10FFFF}\" " ) ) . unwrap( ) ,
1399+ Some ( KdlValue :: String ( "\u{10ffff} " . into( ) ) )
1400+ ) ;
13861401 }
13871402
13881403 #[ test]
@@ -1449,6 +1464,7 @@ mod string_tests {
14491464 string. parse( new_input( "#\" foo\" #" ) ) . unwrap( ) ,
14501465 Some ( KdlValue :: String ( "foo" . into( ) ) )
14511466 ) ;
1467+ assert ! ( string. parse( new_input( "#\" \" \" #" ) ) . is_err( ) ) ;
14521468 }
14531469
14541470 #[ test]
@@ -1686,6 +1702,8 @@ fn slashdash(input: &mut Input<'_>) -> PResult<()> {
16861702#[ test]
16871703fn slashdash_tests ( ) {
16881704 assert ! ( document. parse( new_input( "/- foo bar" ) ) . is_ok( ) ) ;
1705+ assert ! ( document. parse( new_input( "/- foo bar;" ) ) . is_ok( ) ) ;
1706+ assert ! ( document. parse( new_input( "/-n 1;" ) ) . is_ok( ) ) ;
16891707 assert ! ( node. parse( new_input( "/- foo\n bar baz" ) ) . is_ok( ) ) ;
16901708 assert ! ( node_entry. parse( new_input( "/-commented tada" ) ) . is_ok( ) ) ;
16911709 assert ! ( node. parse( new_input( "foo /- { }" ) ) . is_ok( ) ) ;
0 commit comments