Strip leading/trailing whitespace from CSS exprs
When tokenising CSS expressions we now strip leading and trailing whitespace from the input string. This is performed without any checks as a check + `String#strip` ended up being slower compared to just running `String#strip`. On top of that we cache expressions anyway, so the overhead of `String#strip` is very small. Fixes https://gitlab.com/yorickpeterse/oga/issues/187
This commit is contained in:
parent
d1336e760a
commit
886a160c6a
|
@ -23,7 +23,7 @@ module Oga
|
||||||
|
|
||||||
# @param [String] data The data to lex.
|
# @param [String] data The data to lex.
|
||||||
def initialize(data)
|
def initialize(data)
|
||||||
@data = data
|
@data = data.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
# Gathers all the tokens for the input and returns them as an Array.
|
# Gathers all the tokens for the input and returns them as an Array.
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Oga::CSS::Lexer do
|
||||||
|
it 'ignores leading and trailing whitespace' do
|
||||||
|
expect(lex_css(' foo ')).to eq([[:T_IDENT, 'foo']])
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue