You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@rushstack/package-deps-hash

Package Overview
Dependencies
Maintainers
3
Versions
430
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rushstack/package-deps-hash - npm Package Compare versions

Comparing version

to
2.4.33

9

CHANGELOG.md
# Change Log - @rushstack/package-deps-hash
This log was last generated on Fri, 03 Jul 2020 15:09:04 GMT and should not be manually modified.
This log was last generated on Mon, 20 Jul 2020 06:52:33 GMT and should not be manually modified.
## 2.4.33
Mon, 20 Jul 2020 06:52:33 GMT
### Patches
- Fix hashing when a filename contains a space, a special character (ex. ", \), or a unicode character, and fix git hash-object call when long filenames are provided
## 2.4.32

@@ -6,0 +13,0 @@ Fri, 03 Jul 2020 15:09:04 GMT

2

dist/tsdoc-metadata.json

@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.

"packageName": "@microsoft/api-extractor",
"packageVersion": "7.9.0"
"packageVersion": "7.9.2"
}
]
}
import { IPackageDeps } from './IPackageDeps';
/**
* Parses a quoted filename sourced from the output of the "git status" command.
*
* Paths with non-standard characters will be enclosed with double-quotes, and non-standard
* characters will be backslash escaped (ex. double-quotes, non-ASCII characters). The
* escaped chars can be included in one of two ways:
* - backslash-escaped chars (ex. \")
* - octal encoded chars (ex. \347)
*
* See documentation: https://git-scm.com/docs/git-status
*/
export declare function parseGitFilename(filename: string): string;
/**
* Parses the output of the "git ls-tree" command

@@ -4,0 +16,0 @@ */

@@ -5,4 +5,41 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const node_core_library_1 = require("@rushstack/node-core-library");
/**
* Parses a quoted filename sourced from the output of the "git status" command.
*
* Paths with non-standard characters will be enclosed with double-quotes, and non-standard
* characters will be backslash escaped (ex. double-quotes, non-ASCII characters). The
* escaped chars can be included in one of two ways:
* - backslash-escaped chars (ex. \")
* - octal encoded chars (ex. \347)
*
* See documentation: https://git-scm.com/docs/git-status
*/
function parseGitFilename(filename) {
// If there are no double-quotes around the string, then there are no escaped characters
// to decode, so just return
if (!filename.match(/^".+"$/)) {
return filename;
}
// Need to hex encode '%' since we will be decoding the converted octal values from hex
filename = filename.replace(/%/g, '%25');
// Replace all instances of octal literals with percent-encoded hex (ex. '\347\275\221' -> '%E7%BD%91').
// This is done because the octal literals represent UTF-8 bytes, and by converting them to percent-encoded
// hex, we can use decodeURIComponent to get the Unicode chars.
filename = filename.replace(/(?:\\(\d{1,3}))/g, (match, ...[octalValue, index, source]) => {
// We need to make sure that the backslash is intended to escape the octal value. To do this, walk
// backwards from the match to ensure that it's already escaped.
const trailingBackslashes = source
.slice(0, index)
.match(/\\*$/);
return trailingBackslashes && trailingBackslashes.length > 0 && trailingBackslashes[0].length % 2 === 0
? `%${parseInt(octalValue, 8).toString(16)}`
: match;
});
// Finally, decode the filename and unescape the escaped UTF-8 chars
return JSON.parse(decodeURIComponent(filename));
}
exports.parseGitFilename = parseGitFilename;
/**
* Parses the output of the "git ls-tree" command

@@ -24,3 +61,3 @@ */

const hash = matches[3];
const filename = matches[4];
const filename = parseGitFilename(matches[4]);
changes.set(filename, hash);

@@ -66,13 +103,16 @@ }

* - 'RM' == rename with modifications
* filenames == path to the file, or files in the case of files that have been renamed
*/
const [changeType, ...filenames] = line
.trim()
.split(' ')
.filter((linePart) => !!linePart);
if (changeType && filenames && filenames.length > 0) {
const match = line.match(/("(\\"|[^"])+")|(\S+\s*)/g);
if (match && match.length > 1) {
const [changeType, ...filenameMatches] = match;
// We always care about the last filename in the filenames array. In the case of non-rename changes,
// the filenames array only contains one item. In the case of rename changes, the last item in the
// array is the path to the file in the working tree, which is the only one that we care about.
changes.set(filenames[filenames.length - 1], changeType);
// the filenames array only contains one file, so we can join all segments that were split on spaces.
// In the case of rename changes, the last item in the array is the path to the file in the working tree,
// which is the only one that we care about. It is also surrounded by double-quotes if spaces are
// included, so no need to worry about joining different segments
let lastFilename = changeType.startsWith('R')
? filenameMatches[filenameMatches.length - 1]
: filenameMatches.join('');
lastFilename = parseGitFilename(lastFilename);
changes.set(lastFilename, changeType.trimRight());
}

@@ -91,3 +131,5 @@ });

if (filesToHash.length) {
const result = node_core_library_1.Executable.spawnSync('git', ['hash-object', ...filesToHash], { currentWorkingDirectory: packagePath });
// Use --stdin-paths arg to pass the list of files to git in order to avoid issues with
// command length
const result = node_core_library_1.Executable.spawnSync('git', ['hash-object', '--stdin-paths'], { input: filesToHash.map((x) => path.resolve(packagePath, x)).join('\n') });
if (result.status !== 0) {

@@ -128,2 +170,10 @@ throw new Error(`git hash-object exited with status ${result.status}: ${result.stderr}`);

function gitStatus(path) {
/**
* -s - Short format. Will be printed as 'XY PATH' or 'XY ORIG_PATH -> PATH'. Paths with non-standard
* characters will be escaped using double-quotes, and non-standard characters will be backslash
* escaped (ex. spaces, tabs, double-quotes)
* -u - Untracked files are included
*
* See documentation here: https://git-scm.com/docs/git-status
*/
const result = node_core_library_1.Executable.spawnSync('git', ['status', '-s', '-u', '.'], {

@@ -130,0 +180,0 @@ currentWorkingDirectory: path

{
"name": "@rushstack/package-deps-hash",
"version": "2.4.32",
"version": "2.4.33",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet