toStyle icon indicating copy to clipboard operation
toStyle copied to clipboard

toObject will fail for background property with url

Open brokenalarms opened this issue 8 years ago • 1 comments

var toObject = function(str){
    str = (str || '').split(';')

    var result = {}

    str.forEach(function(item){
        var split = item.split(':')

        if (split.length == 2){
            result[split[0].trim()] = split[1].trim()
        }
    })

    return result
}

this would fail for "background: url('http://myurl.com/img.jpg') center / cover". It should parse everything following the ':' up until the next ';'.

brokenalarms avatar Dec 01 '16 17:12 brokenalarms

I'm having this issue myself, but it can get quite trickier than just what @brokenalarms suggests!

Base 64 images will have serious parsing issues using the current approach:

background-image: url("data:image/jpeg;base64,dsdfsdfsdf");

As you can see, there is a ":" and a ";" inside the url, thus making this quite harder to split without proper balanced parsing.

Having said that, I wonder if adding a postcss dependency would be ok with the package owner, as we could use it to properly parse strings.

pedrolamas avatar Jul 24 '19 10:07 pedrolamas