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

module: standardize strip shebang behaviour #12202

Closed

Conversation

seppevs
Copy link
Contributor

@seppevs seppevs commented 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: #12180

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows [commit guidelines][]
Affected core subsystem(s)

module

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. module Issues and PRs related to the module subsystem. labels Apr 4, 2017
@vsemozhetbyt
Copy link
Contributor

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a style nit.

var contLen = content.length;
if (contLen >= 2) {
if (content.charCodeAt(0) === 35/*#*/ &&
content.charCodeAt(1) === 33/*!*/) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: two more spaces of indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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
@seppevs seppevs force-pushed the standardize_strip_shebang_behavior branch from fef91db to 355449d Compare April 4, 2017 10:28
if (contLen === 2) {
// Exact match
content = '';
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just drop the if (contLen === 2) case, it should almost never be hit.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think we should add a test.

/**
* Find end of shebang line and slice it off
*/
function stripShebang(content) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stripHashBang() would be clearer

Copy link
Contributor Author

@seppevs seppevs Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shebang is more commonly used. For example, the Hashbang article on Wikipedia redirects to the Shebang article.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a single data point: I've been a UNIX user for 20+ years and this is the first time I've heard someone call it a hashbang.

// Remove shebang
var contLen = content.length;
if (contLen >= 2) {
if (content.charCodeAt(0) === 35/*#*/ &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this lint? I would expect a space after 35

Copy link
Contributor Author

@seppevs seppevs Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. This code originates from lib/module.js (see master branch)

@not-an-aardvark
Copy link
Contributor

The implementation looks good to me, but I think this should have a regression test for the issue in #12180.

@addaleax
Copy link
Member

Ping @seppevs – do you think you could add a test here? or, the other way around: @not-an-aardvark would you be okay with landing this and keeping #12180 open until we have a test? It would seem like an acceptable second or slightly adventurous first contribution for next week’s Code & Learn.

@jasnell
Copy link
Member

jasnell commented Apr 18, 2017

@not-an-aardvark
Copy link
Contributor

@not-an-aardvark would you be okay with landing this and keeping #12180 open until we have a test?

Sounds good to me.

@addaleax
Copy link
Member

Landed in f971566

@addaleax addaleax closed this Apr 19, 2017
addaleax pushed a commit that referenced this pull request 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]>
@jasnell jasnell mentioned this pull request May 11, 2017
@gibfahn gibfahn added the baking-for-lts PRs that need to wait before landing in a LTS release. label Jun 18, 2017
@gibfahn
Copy link
Member

gibfahn commented Jun 18, 2017

Opting to leave to bake until this has tests.

@MylesBorins MylesBorins removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.