scanner: fix single backslash in raw string (#10890)

pull/10917/head
Daniel Däschle 2021-07-22 16:02:11 +02:00 committed by GitHub
parent b537c9f624
commit ed234188b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -292,7 +292,7 @@ fn (mut ad AnchorData) add_link_targets(line_number int, line string) {
}
}
} else {
query := r'<a\s*id=["\'](?P<link>[a-z0-9\-\_\x7f-\uffff]+)["\']\s*/>'
query := '<a\\s*id=["\'](?P<link>[a-z0-9\\-\\_\\x7f-\\uffff]+)["\']\\s*/>'
mut re := regex.regex_opt(query) or { panic(err) }
res := re.find_all_str(line)

View File

@ -1126,7 +1126,8 @@ fn (mut s Scanner) ident_string() string {
c := s.text[s.pos]
prevc := s.text[s.pos - 1]
// end of string
if c == s.quote && (prevc != slash || (prevc == slash && s.text[s.pos - 2] == slash)) {
if c == s.quote
&& (is_raw || prevc != slash || (prevc == slash && s.text[s.pos - 2] == slash)) {
// handle '123\\' slash at the end
break
}

View File

@ -0,0 +1,3 @@
fn test_raw_string_backslash() {
assert r'\' == r'\'
}