Dockerfile: Fixed strings inside comments (#2428)

Strings inside comments broke comments. Comments are now greedy, so this can't happen anymore.
This commit is contained in:
edukisto 2020-06-21 11:34:19 +03:00 committed by GitHub
parent ff74a61063
commit 37273a6f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 3 deletions

View File

@ -4,7 +4,10 @@ Prism.languages.docker = {
lookbehind: true
},
'string': /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,
'comment': /#.*/,
'comment': {
pattern: /#.*/,
greedy: true
},
'punctuation': /---|\.\.\.|[:[\]{}\-,|>?]/
};

View File

@ -1 +1 @@
Prism.languages.docker={keyword:{pattern:/(^\s*)(?:ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|ONBUILD|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)(?=\s)/im,lookbehind:!0},string:/("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,comment:/#.*/,punctuation:/---|\.\.\.|[:[\]{}\-,|>?]/},Prism.languages.dockerfile=Prism.languages.docker;
Prism.languages.docker={keyword:{pattern:/(^\s*)(?:ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|ONBUILD|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)(?=\s)/im,lookbehind:!0},string:/("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,comment:{pattern:/#.*/,greedy:!0},punctuation:/---|\.\.\.|[:[\]{}\-,|>?]/},Prism.languages.dockerfile=Prism.languages.docker;

View File

@ -2,6 +2,8 @@
<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>

View File

@ -1,11 +1,13 @@
#
# foobar
# "foo" 'bar'
----------------------------------------------------
[
["comment", "#"],
["comment", "# foobar"]
["comment", "# foobar"],
["comment", "# \"foo\" 'bar'"]
]
----------------------------------------------------