Skip to content

Commit 162a7f3

Browse files
authored
Merge pull request #548 from Andrew15-5/catch-backslash-pattern
fix(sublime-syntax): catch backslash pattern
2 parents db4a913 + e6eb4e8 commit 162a7f3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/parsing/syntax_definition.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ where
241241

242242
last_was_escape = c == '\\' && !last_was_escape;
243243
}
244+
if last_was_escape {
245+
reg_str.push('\\');
246+
}
244247
reg_str
245248
}
246249

src/parsing/yaml_load.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,4 +1319,25 @@ mod tests {
13191319
println!("{:?}", valid_indexes);
13201320
assert_eq!(valid_indexes, [0, 1, 5, 6]);
13211321
}
1322+
1323+
#[test]
1324+
fn error_loading_syntax_with_unescaped_backslash() {
1325+
let load_err = SyntaxDefinition::load_from_str(
1326+
r#"
1327+
name: Unescaped Backslash
1328+
scope: source.c
1329+
file_extensions: [test]
1330+
contexts:
1331+
main:
1332+
- match: '\'
1333+
"#,
1334+
false,
1335+
None,
1336+
)
1337+
.unwrap_err();
1338+
match load_err {
1339+
ParseSyntaxError::RegexCompileError(bad_regex, _) => assert_eq!(bad_regex, r"\"),
1340+
_ => panic!("Unexpected error: {load_err}"),
1341+
}
1342+
}
13221343
}

0 commit comments

Comments
 (0)