Skip to content

V2 Can we remove CssParser.convert_uris #157

Open
@stoivo

Description

@stoivo

I am looking to try to remove the use of regex and wonder if we can remove if feature completely CssParser.convert_uris

# Make <tt>url()</tt> links absolute.
#
# Takes a block of CSS and returns it with all relative URIs converted to absolute URIs.
#
# "For CSS style sheets, the base URI is that of the style sheet, not that of the source document."
# per http://www.w3.org/TR/CSS21/syndata.html#uri
#
# Returns a string.
#
# ==== Example
# CssParser.convert_uris("body { background: url('../style/yellow.png?abc=123') };",
# "http://example.org/style/basic.css").inspect
# => "body { background: url('http://example.org/style/yellow.png?abc=123') };"
def self.convert_uris(css, base_uri)
base_uri = Addressable::URI.parse(base_uri) unless base_uri.is_a?(Addressable::URI)
css.gsub(URI_RX) do
uri = Regexp.last_match(1).to_s.gsub(/["']+/, '')
# Don't process URLs that are already absolute
unless uri.match(%r{^[a-z]+://}i)
begin
uri = base_uri.join(uri)
rescue
nil
end
end
"url('#{uri}')"
end
end

It as added 17 years ago 4215785. I think when it's used in premailer we want to have all absolute urls not relative. If thats the reason we should that code should probably be in premailer instead.

Maybe we should just keep it to reduce the braking changes. Just want to ask

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions