Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shebang parsing is slightly different when using the --check flag #12180

Closed
not-an-aardvark opened this issue Apr 3, 2017 · 12 comments
Closed
Labels
cli Issues and PRs related to the Node.js command line interface. good first issue Issues that are suitable for first-time contributors. module Issues and PRs related to the module subsystem.

Comments

@not-an-aardvark
Copy link
Contributor

not-an-aardvark commented Apr 3, 2017

  • Version: 7.8.0 (although this has existed since the --check flag was introduced in 5.0.0)
  • Platform: macOS
  • Subsystem: cli

When loading a module, Node finds the end of a shebang comment by searching for a \r or \n character.

When using the --check flag, Node finds the end of a shebang comment by searching for a character that is not matched by . in a regex.

The characters \u2028 and \u2029 are considered linebreaks in JS, so they aren't matched by . in a regex. As a result, a file with \u2028 or \u2029 in the shebang will load successfully as a module, but will cause an error when parsed with the --check flag.

Example file (contains \u2028 after bin):

#!/usr/bin
/env node
console.log("foo")

The same thing applies when piping code from stdin.

@not-an-aardvark not-an-aardvark added the cli Issues and PRs related to the Node.js command line interface. label Apr 3, 2017
@TimothyGu
Copy link
Member

We should probably have a require('internal/module').stripShebang to standardize the behavior.

@mscdex mscdex added the module Issues and PRs related to the module subsystem. label Apr 3, 2017
seppevs added a commit to seppevs/node that referenced this issue Apr 4, 2017
When loading a module, Node needs to finds the end
of a shebang comment by searching for a \r or \n character.
This behaviour is now standardized into a dedicated
internal module function

Refs: nodejs#12180
addaleax pushed a commit that referenced this issue Apr 19, 2017
When loading a module, Node needs to finds the end
of a shebang comment by searching for a \r or \n character.
This behaviour is now standardized into a dedicated
internal module function

Refs: #12180
PR-URL: #12202
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@gibfahn gibfahn added the good first issue Issues that are suitable for first-time contributors. label Jun 18, 2017
@gibfahn
Copy link
Member

gibfahn commented Jun 18, 2017

Adding good first contribution, although it's more of a second or third contribution. The change landed in #12202, what's needed here is a test or tests for the behaviour.

@guylil
Copy link

guylil commented Jul 19, 2017

Hi,

I am pretty new to contributing here,
Where should I put the test?
Thanks!
@gibfahn

@TimothyGu
Copy link
Member

@guylil Actually sorry, this issue was already fixed in #12202 but we forgot to close it. Doing that now.

@not-an-aardvark
Copy link
Contributor Author

We decided to leave it open because the fix didn't have any tests. #12202 (comment)

@TimothyGu
Copy link
Member

@not-an-aardvark Ah oops.

@guylil
Copy link

guylil commented Jul 20, 2017 via email

@not-an-aardvark
Copy link
Contributor Author

@guylil Thanks for contributing! I think there are a few options for where to put the test: You could either create a new file in test/parallel/, or you could add the test to an existing file, such as test/parallel/test-cli-eval.js.

There is also a guide on writing tests, which can be found here.

@gibfahn
Copy link
Member

gibfahn commented Jul 20, 2017

I am pretty new to contributing here,
Where should I put the test?
Thanks!

So if the test can be run in parallel (if you're not sure, it probably can) then it should go into test/parallel/.

First thing to read/follow is CONTRIBUTING.md, there's also a neat guide to writing tests. Looking at other tests in that directory may help too.

The code that needs tests was added in #12202 (which landed in f971566), so looking at that should be helpful.

Once you have something feel free to raise a PR (You can start the title with WIP - if it's still a Work in Progress). Once you've opened a PR people can help out by suggesting changes.

If you have any more questions feel free to ask them here.

@guylil
Copy link

guylil commented Jul 20, 2017 via email

@ayazhafiz
Copy link
Contributor

@guylil are you still on this? Otherwise, I'd like to work on this.

@not-an-aardvark
Copy link
Contributor Author

Looking at this again, I think it might have already been fixed by 83ebb6d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues and PRs related to the Node.js command line interface. good first issue Issues that are suitable for first-time contributors. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants