Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for special chars in yaml #4105

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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">git@github.com:*/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:
git@github.com:*/copilot:
- "/__tests__/**"

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

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