Skip to content

Issue when HTML attributes have new lines #147

@rvirani1

Description

@rvirani1

We had a case where we were setting an HTML title attribute based on a notes field. Handlebars was correctly escaping all the dangerous characters, but left the newlines since those are valid HTML. However, when we did a diff on that code, we noticed that diff-dom was removing the original attribute and appending pieces of the value as attributes.

Image

We went down the rabbit hole and discovered a flaw in one regex in src/diffDOM/virtual/fromString.ts where this regex doesn't play nicely with newlines.

const attrRE = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g

It should probably be updated to:

const attrRE = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?("[^"]*"|'[^']*')/g

I don't think this should break anything. I'm happy to put up a PR if you're OK with it.

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