csspool 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ token OR
19
19
  token VARIABLE_NAME
20
20
  token CALC_SYM
21
21
  token FONTFACE_SYM
22
+ token UNICODE_RANGE
22
23
 
23
24
  rule
24
25
  document
@@ -34,6 +35,7 @@ rule
34
35
  | import
35
36
  | namespace
36
37
  | body
38
+ |
37
39
  ;
38
40
  charset
39
41
  : CHARSET_SYM STRING SEMI { @handler.charset interpret_string(val[1]), {} }
@@ -558,6 +560,7 @@ rule
558
560
  | function
559
561
  | resolution
560
562
  | VARIABLE_NAME
563
+ | uranges
561
564
  ;
562
565
  function
563
566
  : function S { result = val.first }
@@ -582,6 +585,10 @@ rule
582
585
  result = Terms::Function.new(name, [Terms::String.new(interpret_string_no_quote(parts.last))])
583
586
  }
584
587
  ;
588
+ uranges
589
+ : UNICODE_RANGE COMMA uranges
590
+ | UNICODE_RANGE
591
+ ;
585
592
  calc
586
593
  : CALC_SYM calc_sum RPAREN optional_space {
587
594
  result = Terms::Math.new(val.first.split('(').first, val[1])
@@ -676,22 +683,16 @@ def interpret_string s
676
683
  end
677
684
 
678
685
  def interpret_escapes s
679
- token_exp = /\\([0-9a-fA-F]{1,6}(?:\r\n|\s)?)|\\(.)|(.)/mu
680
- characters = s.scan(token_exp).map do |u_escape, i_escape, ident|
681
- if u_escape
682
- code = u_escape.chomp.to_i 16
686
+ token_exp = /\\(?:([0-9a-fA-F]{1,6}(?:\r\n|\s)?)|(.))/mu
687
+ return s.gsub(token_exp) do |escape_sequence|
688
+ if !$1.nil?
689
+ code = $1.chomp.to_i 16
683
690
  code = 0xFFFD if code > 0x10FFFF
684
- [code].pack('U')
685
- elsif i_escape
686
- if i_escape == "\n"
687
- ''
688
- else
689
- i_escape
690
- end
691
- else
692
- ident
691
+ next [code].pack('U')
693
692
  end
694
- end.join ''
693
+ next '' if $2 == "\n"
694
+ next $2
695
+ end
695
696
  end
696
697
 
697
698
  # override racc's on_error so we can have context in our error messages
@@ -67,7 +67,7 @@ class Tokenizer < Parser
67
67
  when (text = @ss.scan(/U\+[0-9a-fA-F?]{1,6}(-[0-9a-fA-F]{1,6})?/i))
68
68
  action {[:UNICODE_RANGE, st(text)] }
69
69
 
70
- when (text = @ss.scan(/[\s]*\/\*(.|[\s]*)*?\*\/[\s]*/i))
70
+ when (text = @ss.scan(/[\s]*\/\*(.|\s)*?\*\/[\s]*/i))
71
71
  action { next_token }
72
72
 
73
73
  when (text = @ss.scan(/not\([\s]*/i))
@@ -121,7 +121,7 @@ class Tokenizer < Parser
121
121
  when (text = @ss.scan(/[\s]*@(\-[A-Za-z]+\-)?keyframes[\s]*/i))
122
122
  action { [:KEYFRAMES_SYM, st(text)] }
123
123
 
124
- when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|[\s]*)*?\*\/[\s]*)important[\s]*/i))
124
+ when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|\s)*?\*\/[\s]*)important[\s]*/i))
125
125
  action { [:IMPORTANT_SYM, st(text)] }
126
126
 
127
127
  when (text = @ss.scan(/\-\-([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])+/i))
@@ -296,7 +296,7 @@ class Tokenizer < Parser
296
296
  when (text = @ss.scan(/\:/i))
297
297
  action { [:COLON, st(text)] }
298
298
 
299
- when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|[\s]*)*?\*\/[\s]*)important[\s]*/i))
299
+ when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|\s)*?\*\/[\s]*)important[\s]*/i))
300
300
  action { [:IMPORTANT_SYM, st(text)] }
301
301
 
302
302
  when (text = @ss.scan(/[\s]*\{[\s]*/i))
@@ -24,7 +24,7 @@ macro
24
24
  invalid1 "([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*
25
25
  invalid2 '([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*
26
26
  invalid ({invalid1}|{invalid2})
27
- comment \/\*(.|{w})*?\*\/
27
+ comment \/\*(.|\s)*?\*\/
28
28
  variablename \-\-{name}
29
29
 
30
30
  rule
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'benchmark'
2
3
 
3
4
  module CSSPool
4
5
  class TestParser < CSSPool::TestCase
@@ -133,5 +134,88 @@ module CSSPool
133
134
  end
134
135
  end
135
136
 
137
+ def test_only_comments
138
+ CSSPool.CSS <<-eocss
139
+ /* Comment */
140
+ eocss
141
+ end
142
+
143
+ def test_comments
144
+ CSSPool.CSS <<-eocss
145
+ /* Comment */
146
+ a { color: blue;}
147
+ eocss
148
+ end
149
+
150
+ def test_comments_linebreak
151
+ CSSPool.CSS <<-eocss
152
+ /* Multi
153
+ line
154
+ comment */
155
+ a { color: blue;}
156
+ eocss
157
+ end
158
+
159
+ def test_comments_with_asterisk
160
+ CSSPool.CSS <<-eocss
161
+ /* Don't get confused by the * in this comment */
162
+ a { color: blue;}
163
+ eocss
164
+ end
165
+
166
+ def test_broken_comment
167
+ time = Benchmark.measure {
168
+ begin
169
+ CSSPool.CSS <<-eocss
170
+ /*
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+ eocss
187
+ rescue
188
+ end
189
+ }
190
+ assert time.real < 1
191
+ end
192
+
193
+ def test_broken_comment_exclamation
194
+ time = Benchmark.measure {
195
+ begin
196
+ CSSPool.CSS <<-eocss
197
+ !
198
+ /**/
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+ eocss
214
+ rescue
215
+ end
216
+ }
217
+ assert time.real < 1
218
+ end
219
+
136
220
  end
137
221
  end
@@ -68,5 +68,45 @@ module CSSPool
68
68
  a { -webkit-filter: invert() }
69
69
  eocss
70
70
  end
71
+
72
+ def test_unicode_range_single
73
+ CSSPool.CSS <<-eocss
74
+ @font-face {
75
+ font-family: 'Ampersand';
76
+ src: local('Times New Roman');
77
+ unicode-range: U+26;
78
+ }
79
+ eocss
80
+ end
81
+
82
+ def test_unicode_range_range
83
+ CSSPool.CSS <<-eocss
84
+ @font-face {
85
+ font-family: 'Ampersand';
86
+ src: local('Times New Roman');
87
+ unicode-range: U+0025-00FF;
88
+ }
89
+ eocss
90
+ end
91
+
92
+ def test_unicode_range_wildcard
93
+ CSSPool.CSS <<-eocss
94
+ @font-face {
95
+ font-family: 'Ampersand';
96
+ src: local('Times New Roman');
97
+ unicode-range: U+4??;
98
+ }
99
+ eocss
100
+ end
101
+
102
+ def test_unicode_range_wildcard_range
103
+ CSSPool.CSS <<-eocss
104
+ @font-face {
105
+ font-family: 'Ampersand';
106
+ src: local('Times New Roman');
107
+ unicode-range: U+0025-00FF, U+4??;
108
+ }
109
+ eocss
110
+ end
71
111
  end
72
112
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csspool
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-06 00:00:00.000000000 Z
12
+ date: 2014-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  version: '0'
234
234
  requirements: []
235
235
  rubyforge_project: csspool
236
- rubygems_version: 2.2.2
236
+ rubygems_version: 2.4.2
237
237
  signing_key:
238
238
  specification_version: 4
239
239
  summary: CSSPool is a CSS parser