From 353f810cea60184014e8954753c5be38ffd7f413 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 5 Apr 2026 19:38:46 +0200 Subject: [PATCH] Scope invalid escape sequences in double quoted yaml strings Resolves #415 --- ...lime Text Syntax Definition.sublime-syntax | 20 +++++-- .../syntax_test_sublime-syntax.yaml | 57 +++++++++++++++++++ 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/Package/Sublime Text Syntax Definition/Sublime Text Syntax Definition.sublime-syntax b/Package/Sublime Text Syntax Definition/Sublime Text Syntax Definition.sublime-syntax index 8e168458..e3ad8539 100644 --- a/Package/Sublime Text Syntax Definition/Sublime Text Syntax Definition.sublime-syntax +++ b/Package/Sublime Text Syntax Definition/Sublime Text Syntax Definition.sublime-syntax @@ -602,11 +602,10 @@ contexts: scope: punctuation.definition.string.begin.yaml push: - meta_scope: comment.other.quoted.double.sublime-syntax - - match: \\. - scope: constant.character.escape.yaml - match: '"' scope: punctuation.definition.string.end.yaml pop: true + - include: yaml-double-quoted-escapes - match: "'" scope: punctuation.definition.string.begin.yaml @@ -660,12 +659,11 @@ contexts: push: - meta_scope: string.quoted.double.yaml - meta_content_scope: source.regexp.oniguruma - - include: regexp_variable - - match: \\. - scope: constant.character.escape.yaml - match: '"' scope: punctuation.definition.string.end.yaml pop: 2 + - include: yaml-double-quoted-escapes + - include: regexp_variable - match: "'" scope: punctuation.definition.string.begin.yaml @@ -794,3 +792,15 @@ contexts: yaml-tags-anchors: - include: YAML.sublime-syntax#property + + yaml-double-quoted-escapes: + - match: \\[ 0_abefLnNPprtv/\\"] + scope: constant.character.escape.yaml + - match: \\x\h{2} + scope: constant.character.escape.unicode.8bit.yaml + - match: \\u\h{4} + scope: constant.character.escape.unicode.16bit.yaml + - match: \\U\h{8} + scope: constant.character.escape.unicode.32bit.yaml + - match: \\. + scope: invalid.illegal.escape.yaml diff --git a/Package/Sublime Text Syntax Definition/syntax_test_sublime-syntax.yaml b/Package/Sublime Text Syntax Definition/syntax_test_sublime-syntax.yaml index 1e6a2d04..30025238 100644 --- a/Package/Sublime Text Syntax Definition/syntax_test_sublime-syntax.yaml +++ b/Package/Sublime Text Syntax Definition/syntax_test_sublime-syntax.yaml @@ -252,11 +252,13 @@ contexts: - comment: "this is a \"comment" # ^^^^^^^^^^^^^^^^^^^^^ comment.other.quoted.double.sublime-syntax # ^ punctuation.definition.string.begin.yaml +# ^^ constant.character.escape.yaml # ^ punctuation.definition.string.end.yaml comment: 'this is a ''comment' # ^^^^^^^^^^^^^^^^^^^^^ comment.other.quoted.single.sublime-syntax # ^ punctuation.definition.string.begin.yaml +# ^^ constant.character.escape.yaml # ^ punctuation.definition.string.end.yaml - comment: |- @@ -288,6 +290,61 @@ contexts: (?x) # extended group with comments # ^^^^ source.regexp.oniguruma meta.group.extended.regexp # ^ source.regexp.oniguruma comment.line.number-sign.regexp punctuation.definition.comment.regexp + + - match: "(?=\0)" +# ^^ constant.character.escape.yaml + - match: "(?=\a)" +# ^^ constant.character.escape.yaml + - match: "(?=\b)" +# ^^ constant.character.escape.yaml + - match: "(?=\t)" +# ^^ constant.character.escape.yaml + - match: "(?=\n)" +# ^^ constant.character.escape.yaml + - match: "(?=\v)" +# ^^ constant.character.escape.yaml + - match: "(?=\f)" +# ^^ constant.character.escape.yaml + - match: "(?=\r)" +# ^^ constant.character.escape.yaml + - match: "(?=\e)" +# ^^ constant.character.escape.yaml + - match: "(?=\ )" +# ^^ constant.character.escape.yaml + - match: "(?=\")" +# ^^ constant.character.escape.yaml + - match: "(?=\/)" +# ^^ constant.character.escape.yaml + - match: "(?=\\)" +# ^^ constant.character.escape.yaml + - match: "(?=\N)" +# ^^ constant.character.escape.yaml + - match: "(?=\_)" +# ^^ constant.character.escape.yaml + - match: "(?=\L)" +# ^^ constant.character.escape.yaml + - match: "(?=\P)" +# ^^ constant.character.escape.yaml + - match: "(?=\ )" +# ^^ constant.character.escape.yaml + - match: "(?=\ )" +# ^^ constant.character.escape.yaml + - match: "(?=\ )" +# ^^ constant.character.escape.yaml + - match: "(?=\')" +# ^^ invalid.illegal.escape.yaml + - match: "(?=\m)" +# ^^ invalid.illegal.escape.yaml + - match: "(?=\x1234)" +# ^^^^ constant.character.escape.unicode.8bit.yaml +# ^^ - constant.character.escape + - match: "(?=\u123fd)" +# ^^^^^^ constant.character.escape.unicode.16bit.yaml +# ^ - constant.character.escape + - match: "(?=\U123fda3f2)" +# ^^^^^^^^^^ constant.character.escape.unicode.32bit.yaml +# ^ - constant.character.escape + - scope: abc # ^^^^^ string.unquoted.plain.out.yaml storage.type.scope-name.sublime-syntax - meta_scope: abc