Skip to content

Commit c2d29ac

Browse files
authored
fix(yaml) support * and @ characters in keys (#4105)
1 parent 2c615a3 commit c2d29ac

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Core Grammars:
2222
- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK]
2323
- fix(sql) - Fixed sql primary key and foreign key spacing issue [Dxuian]
2424
- fix(cpp) added flat_set and flat_map as a part of cpp 23 version [Lavan]
25+
- fix(yaml) - Fixed special chars in yaml [Dxuian]
2526

2627
New Grammars:
2728

src/languages/yaml.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ export default function(hljs) {
2020
const KEY = {
2121
className: 'attr',
2222
variants: [
23-
// added brackets support
24-
{ begin: /\w[\w :()\./-]*:(?=[ \t]|$)/ },
25-
{ // double quoted keys - with brackets
26-
begin: /"\w[\w :()\./-]*":(?=[ \t]|$)/ },
27-
{ // single quoted keys - with brackets
28-
begin: /'\w[\w :()\./-]*':(?=[ \t]|$)/ },
23+
// added brackets support and special char support
24+
{ begin: /[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/ },
25+
{ // double quoted keys - with brackets and special char support
26+
begin: /"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/ },
27+
{ // single quoted keys - with brackets and special char support
28+
begin: /'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/ },
2929
]
3030
};
31-
31+
3232
const TEMPLATE_VARIABLES = {
3333
className: 'template-variable',
3434
variants: [
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<span class="hljs-comment"># quoted keys</span>
2+
<span class="hljs-attr">&quot;*&quot;:</span>
3+
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;**/.env&quot;</span>
4+
5+
<span class="hljs-comment"># unquoted keys</span>
6+
<span class="hljs-attr">*:</span>
7+
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;**/.env&quot;</span>
8+
9+
<span class="hljs-comment"># special chars in keys:</span>
10+
<span class="hljs-attr">[email protected]:*/copilot:</span>
11+
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;/__tests__/**&quot;</span>
12+
13+
<span class="hljs-comment"># leading special chars in a key</span>
14+
<span class="hljs-attr">*/copilot:</span>
15+
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;/__tests__/**&quot;</span>
16+
17+
<span class="hljs-attr">@gitlab.com:gitlab-org/gitlab-runner.git:</span>
18+
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;/__tests__/**&quot;</span>

test/markup/yaml/special_chars.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# quoted keys
2+
"*":
3+
- "**/.env"
4+
5+
# unquoted keys
6+
*:
7+
- "**/.env"
8+
9+
# special chars in keys:
10+
11+
- "/__tests__/**"
12+
13+
# leading special chars in a key
14+
*/copilot:
15+
- "/__tests__/**"
16+
17+
@gitlab.com:gitlab-org/gitlab-runner.git:
18+
- "/__tests__/**"
19+

0 commit comments

Comments
 (0)