Skip to content

"\uFEFF" in strings removed, breaks React build. #556

@syranide

Description

@syranide

For facebook/react#2247

React uses the encoded "zero width no-break space" "\uFEFF" for an IE8 workaround:
https://github.com/facebook/react/blob/716742dcd7fc7521737c94e7f0ed9d876658a6b7/src/browser/ui/dom/setInnerHTML.js#L66

However, it seems that UglifyJS strips it from the minified build breaking the workaround and throwing an exception. The culprit is apparently:
https://github.com/mishoo/UglifyJS2/blob/master/lib/parse.js#L209

EDIT: Upon further testing it seems that the React build might be double-uglifying for some reason, as I can only reproduce this myself with two uglify passes. It's still very much an issue though as someone could likely concatenate a minified build with their own code and minify that, the error would then show up again.

If I remove it it works as expected, so apparently decoded \uFEFF (even in strings) are removed. We should probably be using \u2060 but due to the decoding of unicode chars even that is not entirely safe. So an option to not decode unicode chars would be preferable as it otherwise requires <meta charset="utf-8"> or <script charset="utf-8" ...>, which many aren't aware of.

Repro: Uglify twice, alert("\uFEFF".length) (1) -> alert("<FEFF>".length) (1) -> alert("".length) (0)

cc @mishoo

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