Skip to content

Commit

Permalink
Dockerfile: Fixed strings inside comments (#2428)
Browse files Browse the repository at this point in the history
Strings inside comments broke comments. Comments are now greedy, so this can't happen anymore.
  • Loading branch information
edukisto committed Jun 21, 2020
1 parent ff74a61 commit 37273a6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion components/prism-docker.js
Expand Up @@ -4,7 +4,10 @@ Prism.languages.docker = {
lookbehind: true
},
'string': /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,
'comment': /#.*/,
'comment': {
pattern: /#.*/,
greedy: true
},
'punctuation': /---|\.\.\.|[:[\]{}\-,|>?]/
};

Expand Down
2 changes: 1 addition & 1 deletion components/prism-docker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/prism-docker.html
Expand Up @@ -2,6 +2,8 @@ <h2>Comments</h2>
<pre><code># These are the comments for a dockerfile.
# I want to make sure $(variables) don't break out,
# and we shouldn't see keywords like ADD or ENTRYPOINT

# I also want to make sure that this "string" and this 'string' don't break out.
</code></pre>

<h2>Full example</h2>
Expand Down
4 changes: 3 additions & 1 deletion tests/languages/docker/comment_feature.test
@@ -1,11 +1,13 @@
#
# foobar
# "foo" 'bar'

----------------------------------------------------

[
["comment", "#"],
["comment", "# foobar"]
["comment", "# foobar"],
["comment", "# \"foo\" 'bar'"]
]

----------------------------------------------------
Expand Down

0 comments on commit 37273a6

Please sign in to comment.