@@ -1229,7 +1229,7 @@ fn escaped_char(input: &mut Input<'_>) -> PResult<char> {
1229
1229
) ) ,
1230
1230
(
1231
1231
"u{" ,
1232
- cut_err ( take_while ( 1 ..6 , AsChar :: is_hex_digit) ) ,
1232
+ cut_err ( take_while ( 1 ..= 6 , AsChar :: is_hex_digit) ) ,
1233
1233
cut_err ( "}" ) ,
1234
1234
)
1235
1235
. context ( cx ( ) . lbl ( "unicode escape char" ) )
@@ -1250,6 +1250,7 @@ fn escaped_char(input: &mut Input<'_>) -> PResult<char> {
1250
1250
/// multi-line-raw-string-body := (unicode - disallowed-literal-code-points)*?
1251
1251
/// ```
1252
1252
fn raw_string ( input : & mut Input < ' _ > ) -> PResult < KdlValue > {
1253
+ let _start_loc = input. location ( ) ;
1253
1254
let hashes: String = repeat ( 1 .., "#" ) . parse_next ( input) ?;
1254
1255
let quotes = alt ( ( ( "\" \" \" " , newline) . take ( ) , "\" " ) ) . parse_next ( input) ?;
1255
1256
let is_multiline = quotes. len ( ) > 1 ;
@@ -1343,7 +1344,17 @@ fn raw_string(input: &mut Input<'_>) -> PResult<KdlValue> {
1343
1344
"\" " . context ( cx ( ) . lbl ( "raw string closing quotes" ) )
1344
1345
} ;
1345
1346
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
+ }
1347
1358
}
1348
1359
1349
1360
/// Like badval, but is able to slurp up invalid raw strings, which contain whitespace.
@@ -1383,6 +1394,10 @@ mod string_tests {
1383
1394
string. parse( new_input( "\" foo\\ u{0a}\" " ) ) . unwrap( ) ,
1384
1395
Some ( KdlValue :: String ( "foo\u{0a} " . into( ) ) )
1385
1396
) ;
1397
+ assert_eq ! (
1398
+ string. parse( new_input( "\" \\ u{10FFFF}\" " ) ) . unwrap( ) ,
1399
+ Some ( KdlValue :: String ( "\u{10ffff} " . into( ) ) )
1400
+ ) ;
1386
1401
}
1387
1402
1388
1403
#[ test]
@@ -1449,6 +1464,7 @@ mod string_tests {
1449
1464
string. parse( new_input( "#\" foo\" #" ) ) . unwrap( ) ,
1450
1465
Some ( KdlValue :: String ( "foo" . into( ) ) )
1451
1466
) ;
1467
+ assert ! ( string. parse( new_input( "#\" \" \" #" ) ) . is_err( ) ) ;
1452
1468
}
1453
1469
1454
1470
#[ test]
@@ -1686,6 +1702,8 @@ fn slashdash(input: &mut Input<'_>) -> PResult<()> {
1686
1702
#[ test]
1687
1703
fn slashdash_tests ( ) {
1688
1704
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( ) ) ;
1689
1707
assert ! ( node. parse( new_input( "/- foo\n bar baz" ) ) . is_ok( ) ) ;
1690
1708
assert ! ( node_entry. parse( new_input( "/-commented tada" ) ) . is_ok( ) ) ;
1691
1709
assert ! ( node. parse( new_input( "foo /- { }" ) ) . is_ok( ) ) ;
0 commit comments