Dockerfile: Fixed strings inside comments (#2428) Strings inside comments broke comments. Comments are now greedy, so this can't happen anymore.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/components/prism-docker.js b/components/prism-docker.js
index c075828..270e66c 100644
--- a/components/prism-docker.js
+++ b/components/prism-docker.js
@@ -4,7 +4,10 @@ Prism.languages.docker = {
lookbehind: true
},
'string': /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,
- 'comment': /#.*/,
+ 'comment': {
+ pattern: /#.*/,
+ greedy: true
+ },
'punctuation': /---|\.\.\.|[:[\]{}\-,|>?]/
};
diff --git a/components/prism-docker.min.js b/components/prism-docker.min.js
index ec55d3a..9c1b73f 100644
--- a/components/prism-docker.min.js
+++ b/components/prism-docker.min.js
@@ -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;
\ No newline at end of file
+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;
\ No newline at end of file
diff --git a/examples/prism-docker.html b/examples/prism-docker.html
index 325d650..206d843 100644
--- a/examples/prism-docker.html
+++ b/examples/prism-docker.html
@@ -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>
diff --git a/tests/languages/docker/comment_feature.test b/tests/languages/docker/comment_feature.test
index 054d602..b29b2be 100644
--- a/tests/languages/docker/comment_feature.test
+++ b/tests/languages/docker/comment_feature.test
@@ -1,11 +1,13 @@
#
# foobar
+# "foo" 'bar'
----------------------------------------------------
[
["comment", "#"],
- ["comment", "# foobar"]
+ ["comment", "# foobar"],
+ ["comment", "# \"foo\" 'bar'"]
]
----------------------------------------------------