css_parser 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d2edab93087cfbb4df3485a29e7da0f744b19b0
4
- data.tar.gz: ea77067eaa3ef29d16f7f056791cc7b443a6e817
3
+ metadata.gz: c2235852355e4765608d07c7f501095cdf831e99
4
+ data.tar.gz: e10526e998c3791112043380ae0e90d170f0af0b
5
5
  SHA512:
6
- metadata.gz: 20375f61b0bcc6acc2d38ab58ba845fe424e6dbabcd92624e833054377d433a9c3ad42022de503101a733d52583fbffa86cddf0da5c6349ae2afef288eb1afea
7
- data.tar.gz: acbf629feb25276a2b77614600c2c4befc95a56784a9de031e4aed181a879747a8f10b577b09af5f12d4d9e3ca58024ddf200d2a7fb7e88ab18ea7c044baf509
6
+ metadata.gz: db43d815d770ac070f6d24a660566467e55ee80bcf88d0a7dd976b9e01c36fe5f22b10d749e28264101e26c4350b35f61b02ff2eab967334e9166d20fd92658a
7
+ data.tar.gz: af2feaacfd1770feb88fd301d8a994feb36735bb224d0a5004420e41b8e2d6e27d682680db64c90df3229f55e908b171f19dbda063a5702a87d213cc61d0246f
@@ -22,7 +22,9 @@ module CssParser
22
22
  # Initial parsing
23
23
  RE_AT_IMPORT_RULE = /\@import\s*(?:url\s*)?(?:\()?(?:\s*)["']?([^'"\s\)]*)["']?\)?([\w\s\,^\]\(\))]*)\)?[;\n]?/
24
24
 
25
- # Array of CSS files that have been loaded.
25
+ MAX_REDIRECTS = 3
26
+
27
+ # Array of CSS files that have been loaded.
26
28
  attr_reader :loaded_uris
27
29
 
28
30
  #--
@@ -438,7 +440,21 @@ module CssParser
438
440
  # TODO: add option to fail silently or throw and exception on a 404
439
441
  #++
440
442
  def read_remote_file(uri) # :nodoc:
441
- return nil, nil unless circular_reference_check(uri.to_s)
443
+ if @redirect_count.nil?
444
+ @redirect_count = 0
445
+ else
446
+ @redirect_count += 1
447
+ end
448
+
449
+ unless circular_reference_check(uri.to_s)
450
+ @redirect_count = nil
451
+ return nil, nil
452
+ end
453
+
454
+ if @redirect_count > MAX_REDIRECTS
455
+ @redirect_count = nil
456
+ return nil, nil
457
+ end
442
458
 
443
459
  src = '', charset = nil
444
460
 
@@ -466,8 +482,13 @@ module CssParser
466
482
  charset = fh.respond_to?(:charset) ? fh.charset : 'utf-8'
467
483
 
468
484
  if res.code.to_i >= 400
485
+ @redirect_count = nil
469
486
  raise RemoteFileError if @options[:io_exceptions]
470
487
  return '', nil
488
+ elsif res.code.to_i == 301 or res.code.to_i == 302
489
+ if res.response['Location'] != nil
490
+ return read_remote_file Addressable::URI.parse(URI::encode(res.response['Location']))
491
+ end
471
492
  end
472
493
 
473
494
  case res['content-encoding']
@@ -489,10 +510,12 @@ module CssParser
489
510
  end
490
511
  end
491
512
  rescue
513
+ @redirect_count = nil
492
514
  raise RemoteFileError if @options[:io_exceptions]
493
515
  return nil, nil
494
516
  end
495
517
 
518
+ @redirect_count = nil
496
519
  return src, charset
497
520
  end
498
521
 
@@ -9,7 +9,7 @@ module CssParser
9
9
 
10
10
  # Array of selector strings.
11
11
  attr_reader :selectors
12
-
12
+
13
13
  # Integer with the specificity to use for this RuleSet.
14
14
  attr_accessor :specificity
15
15
 
@@ -55,7 +55,7 @@ module CssParser
55
55
  @declarations.delete(property)
56
56
  return
57
57
  end
58
-
58
+
59
59
  value.gsub!(/;\Z/, '')
60
60
  is_important = !value.gsub!(CssParser::IMPORTANT_IN_PROPERTY_RX, '').nil?
61
61
  property = property.downcase.strip
@@ -173,7 +173,7 @@ module CssParser
173
173
  split_declaration(k, "#{k}-color", value.slice!(CssParser::RE_COLOUR))
174
174
  split_declaration(k, "#{k}-style", value.slice!(CssParser::RE_BORDER_STYLE))
175
175
 
176
- @declarations.delete(k)
176
+ @declarations.delete(k)
177
177
  end
178
178
  end
179
179
 
@@ -182,20 +182,20 @@ module CssParser
182
182
  def expand_dimensions_shorthand! # :nodoc:
183
183
  {'margin' => 'margin-%s',
184
184
  'padding' => 'padding-%s',
185
- 'border-color' => 'border-%s-color',
186
- 'border-style' => 'border-%s-style',
185
+ 'border-color' => 'border-%s-color',
186
+ 'border-style' => 'border-%s-style',
187
187
  'border-width' => 'border-%s-width'}.each do |property, expanded|
188
188
 
189
189
  next unless @declarations.has_key?(property)
190
-
190
+
191
191
  value = @declarations[property][:value]
192
192
 
193
193
  # RGB and HSL values in borders are the only units that can have spaces (within params).
194
- # We cheat a bit here by stripping spaces after commas in RGB and HSL values so that we
194
+ # We cheat a bit here by stripping spaces after commas in RGB and HSL values so that we
195
195
  # can split easily on spaces.
196
196
  #
197
197
  # TODO: rgba, hsl, hsla
198
- value.gsub!(RE_COLOUR) { |c| c.gsub(/[\s]+/, '') }
198
+ value.gsub!(RE_COLOUR) { |c| c.gsub(/(\s?\,\s?)/, ',') }
199
199
 
200
200
  matches = value.strip.split(/[\s]+/)
201
201
 
@@ -348,14 +348,14 @@ module CssParser
348
348
 
349
349
  create_shorthand_properties! BACKGROUND_PROPERTIES, 'background'
350
350
  end
351
-
351
+
352
352
  # Combine border-color, border-style and border-width into border
353
353
  # Should be run after create_dimensions_shorthand!
354
354
  #
355
355
  # TODO: this is extremely similar to create_background_shorthand! and should be combined
356
356
  def create_border_shorthand! # :nodoc:
357
357
  values = []
358
-
358
+
359
359
  ['border-width', 'border-style', 'border-color'].each do |property|
360
360
  if @declarations.has_key?(property) and not @declarations[property][:is_important]
361
361
  # can't merge if any value contains a space (i.e. has multiple values)
@@ -373,16 +373,16 @@ module CssParser
373
373
  @declarations['border'] = {:value => values.join(' ')}
374
374
  end
375
375
  end
376
-
377
- # Looks for long format CSS dimensional properties (margin, padding, border-color, border-style and border-width)
376
+
377
+ # Looks for long format CSS dimensional properties (margin, padding, border-color, border-style and border-width)
378
378
  # and converts them into shorthand CSS properties.
379
379
  def create_dimensions_shorthand! # :nodoc:
380
380
  directions = ['top', 'right', 'bottom', 'left']
381
381
 
382
382
  {'margin' => 'margin-%s',
383
383
  'padding' => 'padding-%s',
384
- 'border-color' => 'border-%s-color',
385
- 'border-style' => 'border-%s-style',
384
+ 'border-color' => 'border-%s-color',
385
+ 'border-style' => 'border-%s-style',
386
386
  'border-width' => 'border-%s-width'}.each do |property, expanded|
387
387
 
388
388
  top, right, bottom, left = ['top', 'right', 'bottom', 'left'].map { |side| expanded % side }
@@ -396,7 +396,7 @@ module CssParser
396
396
  directions.each { |d| values[d.to_sym] = @declarations[expanded % d][:value].downcase.strip }
397
397
 
398
398
  if values[:left] == values[:right]
399
- if values[:top] == values[:bottom]
399
+ if values[:top] == values[:bottom]
400
400
  if values[:top] == values[:left] # All four sides are equal
401
401
  new_value = values[:top]
402
402
  else # Top and bottom are equal, left and right are equal
@@ -419,8 +419,8 @@ module CssParser
419
419
  end
420
420
 
421
421
 
422
- # Looks for long format CSS font properties (e.g. <tt>font-weight</tt>) and
423
- # tries to convert them into a shorthand CSS <tt>font</tt> property. All
422
+ # Looks for long format CSS font properties (e.g. <tt>font-weight</tt>) and
423
+ # tries to convert them into a shorthand CSS <tt>font</tt> property. All
424
424
  # font properties must be present in order to create a shorthand declaration.
425
425
  def create_font_shorthand! # :nodoc:
426
426
  ['font-style', 'font-variant', 'font-weight', 'font-size',
@@ -468,17 +468,17 @@ module CssParser
468
468
 
469
469
  if @declarations.has_key?(dest)
470
470
  #puts "dest #{dest} already exists"
471
-
471
+
472
472
  if @declarations[dest][:order] > @declarations[src][:order]
473
- #puts "skipping #{dest}:#{v} due to order "
473
+ #puts "skipping #{dest}:#{v} due to order "
474
474
  return
475
475
  else
476
- @declarations[dest] = {}
476
+ @declarations[dest] = {}
477
477
  end
478
478
  end
479
- @declarations[dest] = @declarations[src].merge({:value => v.to_s.strip})
479
+ @declarations[dest] = @declarations[src].merge({:value => v.to_s.strip})
480
480
  end
481
-
481
+
482
482
  def parse_declarations!(block) # :nodoc:
483
483
  @declarations = {}
484
484
 
@@ -1,3 +1,3 @@
1
1
  module CssParser
2
- VERSION = "1.4.2".freeze
2
+ VERSION = "1.4.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-17 00:00:00.000000000 Z
11
+ date: 2016-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 2.4.5.1
59
+ rubygems_version: 2.5.1
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: Ruby CSS parser.