Skip to content

Commit 8c394c0

Browse files
committed
issue #13 - problem with stripping when two =
fixed greedy regexp
1 parent 94b3991 commit 8c394c0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/coderay/scanners/bash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def scan_tokens encoder, options
155155
next
156156
elsif match = scan(PRE_CONSTANTS)
157157
kind = :predefined_constant
158-
elsif match = scan(/[^\s'"]*[A-Za-z_][A-Za-z_0-9]*\+?=/)
158+
elsif match = scan(/[^\s'"]*?[A-Za-z_][A-Za-z_0-9]*\+?=/)
159159
match =~ /(.*?)([A-Za-z_][A-Za-z_0-9]*)(\+?=)/
160160
str = $1
161161
pre = $2

test/keep_path.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
sudo qemu-kvm -m 768 \
4+
-boot d \
5+
-drive file=/bak/kvm/salix.qcow,cache=writeback \
6+
-cdrom /ntfs-d/ISO/salix64-openbox-14.1.iso -vnc :3
7+

test/test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@ def test_0010_Array
8686
end
8787

8888
end
89+
90+
91+
class TestKeepPath < Test::Unit::TestCase
92+
93+
def test_0010_Array
94+
file = File.join($current_dir, "keep_path.sh")
95+
assert_equal(["#!/bin/sh", :directive, "\n", :end_line, "\n", :end_line, "sudo", :ident, " ", :space, "qemu", :ident, "-", :operator, "kvm", :ident, " ", :space, "-", :operator, "m", :ident, " ", :space, "768", :integer, " ", :space, "\\", :plain, "\n", :end_line, " ", :space, "-", :operator, "boot", :ident, " ", :space, "d", :ident, " ", :space, "\\", :plain, "\n", :end_line, " ", :space, "-", :operator, "drive", :ident, " ", :space, "file", :instance_variable, "=", :operator, "/bak/kvm/salix.qcow,cache=", :plain, "writeback", :ident, " ", :space, "\\", :plain, "\n", :end_line, " ", :space, "-", :operator, "cdrom", :ident, " ", :space, "/", :plain, "ntfs", :ident, "-", :operator, "d", :ident, "/", :plain, "ISO", :ident, "/", :plain, "salix64", :ident, "-", :operator, "openbox", :ident, "-", :operator, "14.1.", :float, "iso", :ident, " ", :space, "-", :operator, "vnc", :ident, " ", :space, ":", :reserved, "3", :integer, "\n", :end_line, "\n", :end_line],
96+
CodeRay.scan(File.read(file), :bash).tokens)
97+
end
98+
99+
end

0 commit comments

Comments
 (0)