Repository navigation
node -c rejects BOM before #!, but node accepts it #27767
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Description
Activity
i'd expect a failure if both are present. whether we fail because BOM is invalid js or because a shebang is invalid js seems less relevant. to do this i'd combine them into a stripShebangOrBOM function which operates on the first few bytes of the file all at once so we can't accidentally strip one and then the other.
(Strictly speaking the BOM is valid - it's parsed as whitespace.)
that's interesting. i'd still say our logic is wrong here. BOM and shebang only have meaning as the first bytes of the file.
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
on May 19, 2019 I made this, if the logic seems alright I'll PR it. 429bf4a
- added 2 commits that reference this issue
on Jan 8, 2020 - added a commit that references this issue
on Feb 6, 2020
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Version: v12.1.0
The bug is that
check_syntax.jscallstripShebangbeforestripBOM, but the actual loader calls stripBOM before stripShebag.It's not totally clear which behavior is desired. The original bug which lead to the introduction of
stripBOMactually had a script with a BOM preceding the#!, though the test included in that commit doesn't. But unix systems generally require the#!to be the first two bytes for it to be parsed as an interpreter directive, which means it cannot be preceded by a BOM.