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:
Yorick Peterse 2018-01-04 22:02:50 +01:00
parent d1336e760a
commit 886a160c6a
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
2 changed files with 8 additions and 1 deletions

View File

@ -23,7 +23,7 @@ module Oga
# @param [String] data The data to lex.
def initialize(data)
@data = data
@data = data.strip
end
# Gathers all the tokens for the input and returns them as an Array.

View File

@ -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