Skip to content

Commit a4599f5

Browse files
committed
fix strings starting with comment character
1 parent 421953c commit a4599f5

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/coderay/scanners/bash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def scan_tokens encoder, options
8585
kind = :directive
8686
elsif match = scan(/\s*#.*/)
8787
kind = :comment
88-
elsif match = scan(/.#/)
88+
elsif match = scan(/[^"]#/)
8989
kind = :ident
9090
elsif match = scan(/(?:\. |source ).*/)
9191
kind = :reserved

test/string_comment.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
echo "#output a comment" > foo
2+
echo "more" >> foo # so this is a comment now

test/test.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@ def test_0020_ErbBash_Ignoring_Errors
3030
CodeRay.scan(File.read(eb_file), :erb_bash).tokens
3131
)
3232
end
33-
34-
def test_0010_ErbBash_to_html
35-
eb_file = File.join($current_dir, "function.sh")
36-
assert_nothing_raised {
37-
CodeRay.scan(File.read(eb_file), :erb_bash, :ignore_errors => false).html
38-
}
39-
end
40-
33+
4134
def test_0030_heredoc
4235
file = File.join($current_dir, "heredoc.sh")
4336
assert_equal(
@@ -53,5 +46,20 @@ def test_0040_nested_shell
5346
CodeRay.scan(File.read(file), :bash).tokens
5447
)
5548
end
49+
50+
def test_0050_ErbBash_to_html
51+
eb_file = File.join($current_dir, "function.sh")
52+
assert_nothing_raised {
53+
CodeRay.scan(File.read(eb_file), :erb_bash, :ignore_errors => false).html
54+
}
55+
end
56+
57+
def test_0060_Comments_in_strings
58+
eb_file = File.join($current_dir, "string_comment.sh")
59+
assert_equal(
60+
["echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "#output a comment", :content, "\"", :delimiter, :end_group, :string, " ", :space, ">", :bin, " ", :space, "foo", :ident, "\n", :end_line, "echo", :method, " ", :space, :begin_group, :string, "\"", :delimiter, "more", :content, "\"", :delimiter, :end_group, :string, " ", :space, ">", :bin, ">", :bin, " ", :space, "foo", :ident, " # so this is a comment now", :comment, "\n", :end_line],
61+
CodeRay.scan(File.read(eb_file), :bash).tokens
62+
)
63+
end
5664

5765
end

0 commit comments

Comments
 (0)