Skip to content

Commit 7aa6ea0

Browse files
committed
Merge branch 'master' into possible-speedups
Conflicts: lib/coderay/encoders/html.rb
2 parents bc4854f + 31a09b7 commit 7aa6ea0

File tree

7 files changed

+29
-30
lines changed

7 files changed

+29
-30
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ rvm:
33
- ree
44
- 1.9.3
55
- 2.0.0
6+
- 2.1
7+
- 2.2
68
- ruby-head
79
- jruby-18mode
810
- jruby-19mode

Changes.textile

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ h1=. CodeRay Version History
22

33
p=. _This files lists all changes in the CodeRay library since the 0.9.8 release._
44

5+
h2. Changes in 1.1.1
6+
7+
* SQL scanner: fix open strings [#163, thanks to Adam]
8+
59
h2. Changes in 1.1
610

711
New scanners:

Gemfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ gemspec
66
# Add dependencies to develop your gem here.
77
# Include everything needed to run rake, tests, features, etc.
88
group :development do
9-
gem "bundler", ">= 1.0.0"
9+
gem "bundler"
1010
gem "rake"
1111
gem "RedCloth", RUBY_PLATFORM == 'java' ? ">= 4.2.7" : ">= 4.0.3"
12-
gem "term-ansicolor", '~> 1.2.2'
13-
gem "shoulda-context", "~> 1.1.2"
12+
gem "term-ansicolor"
13+
gem "shoulda-context"
14+
gem "test-unit"
1415
gem "json" if RUBY_VERSION < '1.9'
1516
gem "rdoc"
1617
end

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You put your code in, and you get it back colored; Keywords, strings, floats, co
1616

1717
### Dependencies
1818

19-
CodeRay needs Ruby 1.8.7, 1.9.3 or 2.0. It also runs on JRuby.
19+
CodeRay needs Ruby 1.8.7, 1.9.3 or 2.0+. It also runs on JRuby.
2020

2121
## Example Usage
2222

lib/coderay/encoders/html.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def make_escape_cache options
280280
if options[:tab_width] == DEFAULT_OPTIONS[:tab_width]
281281
HTML_ESCAPE
282282
else
283-
HTML_ESCAPE.merge("\t" => ' ' * options[:tab_width])
283+
HTML_ESCAPE.merge("\t" => options[:tab_width] ? ' ' * options[:tab_width] : "\t")
284284
end
285285

286286
Hash.new do |cache, text|

lib/coderay/scanners/sql.rb

+16-24
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class SQL < Scanner
5757

5858
STRING_PREFIXES = /[xnb]|_\w+/i
5959

60+
STRING_CONTENT_PATTERN = {
61+
'"' => / (?: [^\\"] | "" )+ /x,
62+
"'" => / (?: [^\\'] | '' )+ /x,
63+
'`' => / (?: [^\\`] | `` )+ /x,
64+
}
65+
6066
def scan_tokens encoder, options
6167

6268
state = :initial
@@ -115,40 +121,26 @@ def scan_tokens encoder, options
115121
end
116122

117123
elsif state == :string
118-
if match = scan(/[^\\"'`]+/)
119-
string_content << match
120-
next
124+
if match = scan(STRING_CONTENT_PATTERN[string_type])
125+
encoder.text_token match, :content
121126
elsif match = scan(/["'`]/)
122127
if string_type == match
123128
if peek(1) == string_type # doubling means escape
124-
string_content << string_type << getch
125-
next
126-
end
127-
unless string_content.empty?
128-
encoder.text_token string_content, :content
129-
string_content = ''
129+
encoder.text_token match + getch, :content
130+
else
131+
encoder.text_token match, :delimiter
132+
encoder.end_group :string
133+
state = :initial
134+
string_type = nil
130135
end
131-
encoder.text_token match, :delimiter
132-
encoder.end_group :string
133-
state = :initial
134-
string_type = nil
135136
else
136-
string_content << match
137+
encoder.text_token match, :content
137138
end
138139
elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
139-
unless string_content.empty?
140-
encoder.text_token string_content, :content
141-
string_content = ''
142-
end
143140
encoder.text_token match, :char
144141
elsif match = scan(/ \\ . /mox)
145-
string_content << match
146-
next
142+
encoder.text_token match, :content
147143
elsif match = scan(/ \\ | $ /x)
148-
unless string_content.empty?
149-
encoder.text_token string_content, :content
150-
string_content = ''
151-
end
152144
encoder.text_token match, :error unless match.empty?
153145
encoder.end_group :string
154146
state = :initial

lib/coderay/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module CodeRay
2-
VERSION = '1.1.0'
2+
VERSION = '1.1.1'
33
end

0 commit comments

Comments
 (0)