You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by dp...@apache.org on 2018/08/22 17:10:34 UTC
[cordova-lib] 02/04: Fix reading garbage shebang in HooksRunner.spec
This is an automated email from the ASF dual-hosted git repository.
dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git
commit 068bd289be211bfa470220fa6031c3634a1ee90d
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Wed Aug 22 00:29:23 2018 +0200
Fix reading garbage shebang in HooksRunner.spec
Fixes #653
---
package.json | 1 +
src/hooks/HooksRunner.js | 21 ++++++++-------------
2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/package.json b/package.json
index e6f34a5..07988d9 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
"plist": "2.0.1",
"properties-parser": "0.3.1",
"q": "^1.5.1",
+ "read-chunk": "^2.1.0",
"semver": "^5.3.0",
"shelljs": "0.3.0",
"tar": "^4.4.1",
diff --git a/src/hooks/HooksRunner.js b/src/hooks/HooksRunner.js
index 0f19e84..ce8e551 100644
--- a/src/hooks/HooksRunner.js
+++ b/src/hooks/HooksRunner.js
@@ -19,6 +19,7 @@ const fs = require('fs');
const os = require('os');
const path = require('path');
const Q = require('q');
+const readChunk = require('read-chunk');
const cordovaUtil = require('../cordova/util');
const scriptsFinder = require('./scriptsFinder');
@@ -235,23 +236,17 @@ function runScriptViaChildProcessSpawn (script, context) {
/**
* Extracts shebang interpreter from script' source. */
function extractSheBangInterpreter (fullpath) {
- var fileChunk;
- var octetsRead;
- var fileData;
- var hookFd = fs.openSync(fullpath, 'r');
- try {
- // this is a modern cluster size. no need to read less
- fileData = new Buffer(4096); // eslint-disable-line
- octetsRead = fs.readSync(hookFd, fileData, 0, 4096, 0);
- fileChunk = fileData.toString();
- } finally {
- fs.closeSync(hookFd);
- }
+ // this is a modern cluster size. no need to read less
+ const chunkSize = 4096;
+ const fileData = readChunk.sync(fullpath, 0, chunkSize);
+ const fileChunk = fileData.toString();
var hookCmd, shMatch;
// Filter out /usr/bin/env so that "/usr/bin/env node" works like "node".
var shebangMatch = fileChunk.match(/^#!(?:\/usr\/bin\/env )?([^\r\n]+)/m);
- if (octetsRead == 4096 && !fileChunk.match(/[\r\n]/)) { events.emit('warn', 'shebang is too long for "' + fullpath + '"'); } // eslint-disable-line eqeqeq
+ if (fileData.length === chunkSize && !fileChunk.match(/[\r\n]/)) {
+ events.emit('warn', 'shebang is too long for "' + fullpath + '"');
+ }
if (shebangMatch) { hookCmd = shebangMatch[1]; }
// Likewise, make /usr/bin/bash work like "bash".
if (hookCmd) { shMatch = hookCmd.match(/bin\/((?:ba)?sh)$/); }
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org