Commit 37273a6f79d40f1196629007291bd9fc7d76db9c

edukisto 2020-06-21T11:34:19

Dockerfile: Fixed strings inside comments (#2428) Strings inside comments broke comments. Comments are now greedy, so this can't happen anymore.

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'"]
 ]
 
 ----------------------------------------------------