Skip to content

Commit

Permalink
Fix the escape of the matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
nodece committed Jun 14, 2019
1 parent 54d7c89 commit cab0ceb
Show file tree
Hide file tree
Showing 3 changed files with 892 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"devDependencies": {
"@types/ip": "^0.0.31",
"@types/jest": "^24.0.11",
"@types/jscodeshift": "^0.6.0",
"@types/lodash": "^4.14.113",
"@types/node": "^10.5.3",
"coveralls": "^3.0.2",
Expand All @@ -30,6 +31,7 @@
"dependencies": {
"expression-eval": "^2.0.0",
"ip": "^1.1.5",
"jscodeshift": "^0.6.4",
"lodash": "^4.17.10"
},
"files": [
Expand Down
16 changes: 16 additions & 0 deletions src/model/model.ts
Expand Up @@ -15,6 +15,7 @@
import * as _ from 'lodash';
import * as rbac from '../rbac';
import * as util from '../util';
import * as j from 'jscodeshift';
import { Config } from '../config';
import { Assertion } from './assertion';
import { logPrint } from '../log';
Expand Down Expand Up @@ -83,6 +84,21 @@ export class Model {
tokens[i] = key + '_' + tokens[i];
}
ast.tokens = tokens;
} else if (sec === 'm') {
const mAST = j(util.removeComments(value));
let hasEscape = false;

mAST.find(j.Literal).forEach(path => {
let n = path.value.value;
if (typeof n === 'string' && n.includes('.')) {
hasEscape = true;
n = n.replace(/\./g, '\\.');
j(path).replaceWith(j.literal(n));
}
});

value = util.escapeAssertion(mAST.toSource());
ast.value = hasEscape ? value.replace(/\\\\./g, '.') : value;
} else {
ast.value = util.removeComments(util.escapeAssertion(value));
}
Expand Down

0 comments on commit cab0ceb

Please sign in to comment.