Skip to content

Property value with newlines leads to corrupt data #14

@JustinBeckwith

Description

@JustinBeckwith

I recently started using this library ... and thank you for this! My parsing logic was very bad and wrong. I got a user issue reported over here:
JustinBeckwith/linkinator#511

Which basically boils down to the library not really properly parsing srcset values if there are gratuitous newlines and spaces strewn about. The following shows what's happenin:

import {parseSrcset} from 'srcset';

let value, result;

value = `/docs/v1/assets/img/bootstrap-icons.png,
                                                    /docs/v1/assets/img/bootstrap-icons@2x.png 2x`;
result = parseSrcset(value);
console.log(result);

// result: [ { url: '/docs/v1/assets/img/bootstrap-icons.png,', density: 2 } ]

value = '/docs/v1/assets/img/bootstrap-icons.png, /docs/v1/assets/img/bootstrap-icons@2x.png 2x';
result = parseSrcset(value);
console.log(result);

// result: [
//   { url: '/docs/v1/assets/img/bootstrap-icons.png' },
//   { url: '/docs/v1/assets/img/bootstrap-icons@2x.png', density: 2 }
// ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions