Skip to content

Commit

Permalink
Merge pull request #315 from ericmorand/issue_314
Browse files Browse the repository at this point in the history
Fix issue #314
  • Loading branch information
ericmorand authored Feb 13, 2019
2 parents 7ab824a + 5aa73c0 commit 4fec095
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
9 changes: 7 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"camelcase": "^4.1.0",
"capitalize": "^1.0.0",
"crypto-js": "^3.1.9-1",
"esrever": "^0.2.0",
"fs-extra": "^5.0.0",
"htmlspecialchars": "^1.0.5",
Expand Down
6 changes: 4 additions & 2 deletions src/lib/cache/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {TwingEnvironment} from "../environment";
let fs = require('fs-extra');
let path = require('path');
let tmp = require('tmp');
let crypto = require('crypto');

const sha256 = require('crypto-js/sha256');
const hex = require('crypto-js/enc-hex');

/**
* Implements a cache on the filesystem.
Expand All @@ -29,7 +31,7 @@ export class TwingCacheFilesystem implements TwingCacheInterface {
}

generateKey(name: string, className: string) {
let hash: string = crypto.createHash('sha256').update(className).digest('hex');
let hash: string = hex.stringify(sha256(className));

return path.join(
this.directory,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {ksort} from "./helper/ksort";

const substr_count = require('locutus/php/strings/substr_count');
const addcslashes = require('locutus/php/strings/addcslashes');
const crypto = require('crypto');
const sha256 = require('crypto-js/sha256');
const hex = require('crypto-js/enc-hex');

export class TwingCompiler {
private lastLine: number;
Expand Down Expand Up @@ -302,6 +303,6 @@ export class TwingCompiler {
}

getVarName(prefix: string = '__internal_'): string {
return `${prefix}${crypto.createHash('sha256').update('TwingCompiler::getVarName' + this.varNameSalt++).digest('hex')}`;
return `${prefix}${hex.stringify(sha256('TwingCompiler::getVarName' + this.varNameSalt++))}`;
}
}
7 changes: 4 additions & 3 deletions src/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ import {TwingSandboxSecurityNotAllowedTagError} from "./sandbox/security-not-all
import {TwingSourceMapNode, TwingSourceMapNodeConstructor} from "./source-map/node";

const path = require('path');
const crypto = require('crypto');
const sha256 = require('crypto-js/sha256');
const hex = require('crypto-js/enc-hex');

/**
* * Available options:
Expand Down Expand Up @@ -363,7 +364,7 @@ export abstract class TwingEnvironment extends EventEmitter {
getTemplateClass(name: string, index: number = null, from: TwingSource = null) {
let key = this.getLoader().getCacheKey(name, from) + this.optionsHash;

return this.templateClassPrefix + crypto.createHash('sha256').update(key).digest('hex') + (index === null ? '' : '_' + index);
return this.templateClassPrefix + hex.stringify(sha256(key)) + (index === null ? '' : '_' + index);
}

/**
Expand Down Expand Up @@ -535,7 +536,7 @@ return module.exports;
*/
createTemplate(template: string) {
let result: TwingTemplate;
let name = `__string_template__${crypto.createHash('sha256').update(template).digest('hex')}`;
let name = `__string_template__${hex.stringify(sha256(template))}`;
let current = this.getLoader();

let loader = new TwingLoaderChain([
Expand Down
5 changes: 3 additions & 2 deletions src/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {push} from "./helper/push";

const ctype_space = require('locutus/php/ctype/ctype_space');
const mt_rand = require('locutus/php/math/mt_rand');
const crypto = require('crypto');
const sha256 = require('crypto-js/sha256');
const hex = require('crypto-js/enc-hex');

class TwingParserStackEntry {
stream: TwingTokenStream;
Expand Down Expand Up @@ -65,7 +66,7 @@ export class TwingParser {
}

getVarName(prefix: string = '__internal_'): string {
return `${prefix}${crypto.createHash('sha256').update('TwingParser::getVarName' + this.stream.getSourceContext().getCode() + this.varNameSalt++).digest('hex')}`;
return `${prefix}${hex.stringify(sha256('TwingParser::getVarName' + this.stream.getSourceContext().getCode() + this.varNameSalt++))}`;
}

parse(stream: TwingTokenStream, test: Array<any> = null, dropNeedle: boolean = false): TwingNodeModule {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/profiler/node-visitor/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {TwingNodeBody} from "../../node/body";
import {TwingProfilerNodeEnterProfile} from "../node/enter-profile";
import {TwingProfilerNodeLeaveProfile} from "../node/leave-profile";

const crypto = require('crypto');
const sha256 = require('crypto-js/sha256');
const hex = require('crypto-js/enc-hex');

export class TwingProfilerNodeVisitorProfiler extends TwingBaseNodeVisitor {
private extensionName: string;
Expand Down Expand Up @@ -72,7 +73,7 @@ export class TwingProfilerNodeVisitorProfiler extends TwingBaseNodeVisitor {
}

private getVarName(): string {
return `__internal_${crypto.createHash('sha256').update(this.extensionName).digest('hex')}`;
return `__internal_${hex.stringify(sha256(this.extensionName))}`;
}

getPriority() {
Expand Down

0 comments on commit 4fec095

Please sign in to comment.