Skip to content

Commit

Permalink
fix(yaml) support * and @ characters in keys (#4105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dxuian authored Oct 20, 2024
1 parent 2c615a3 commit c2d29ac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Core Grammars:
- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK]
- fix(sql) - Fixed sql primary key and foreign key spacing issue [Dxuian]
- fix(cpp) added flat_set and flat_map as a part of cpp 23 version [Lavan]
- fix(yaml) - Fixed special chars in yaml [Dxuian]

New Grammars:

Expand Down
14 changes: 7 additions & 7 deletions src/languages/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export default function(hljs) {
const KEY = {
className: 'attr',
variants: [
// added brackets support
{ begin: /\w[\w :()\./-]*:(?=[ \t]|$)/ },
{ // double quoted keys - with brackets
begin: /"\w[\w :()\./-]*":(?=[ \t]|$)/ },
{ // single quoted keys - with brackets
begin: /'\w[\w :()\./-]*':(?=[ \t]|$)/ },
// added brackets support and special char support
{ begin: /[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/ },
{ // double quoted keys - with brackets and special char support
begin: /"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/ },
{ // single quoted keys - with brackets and special char support
begin: /'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/ },
]
};

const TEMPLATE_VARIABLES = {
className: 'template-variable',
variants: [
Expand Down
18 changes: 18 additions & 0 deletions test/markup/yaml/special_chars.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<span class="hljs-comment"># quoted keys</span>
<span class="hljs-attr">&quot;*&quot;:</span>
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;**/.env&quot;</span>

<span class="hljs-comment"># unquoted keys</span>
<span class="hljs-attr">*:</span>
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;**/.env&quot;</span>

<span class="hljs-comment"># special chars in keys:</span>
<span class="hljs-attr">[email protected]:*/copilot:</span>
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;/__tests__/**&quot;</span>

<span class="hljs-comment"># leading special chars in a key</span>
<span class="hljs-attr">*/copilot:</span>
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;/__tests__/**&quot;</span>

<span class="hljs-attr">@gitlab.com:gitlab-org/gitlab-runner.git:</span>
<span class="hljs-bullet">-</span> <span class="hljs-string">&quot;/__tests__/**&quot;</span>
19 changes: 19 additions & 0 deletions test/markup/yaml/special_chars.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# quoted keys
"*":
- "**/.env"

# unquoted keys
*:
- "**/.env"

# special chars in keys:
[email protected]:*/copilot:
- "/__tests__/**"

# leading special chars in a key
*/copilot:
- "/__tests__/**"

@gitlab.com:gitlab-org/gitlab-runner.git:
- "/__tests__/**"

0 comments on commit c2d29ac

Please sign in to comment.