-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
191 additions
and
184 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", | ||
"javascript": { | ||
"formatter": { | ||
"arrowParentheses": "always", | ||
"indentStyle": "space", | ||
"semicolons": "asNeeded", | ||
"trailingComma": "all", | ||
"lineWidth": 100, | ||
"quoteStyle": "single" | ||
} | ||
}, | ||
"linter": { | ||
"rules": { | ||
"style": { | ||
"useConst": "off", | ||
"noVar": "off", | ||
"noParameterAssign": "off", | ||
"useTemplate": "off" | ||
}, | ||
"correctness": { | ||
"noInnerDeclarations": "off" | ||
}, | ||
"suspicious": { | ||
"noGlobalIsNan": "off" | ||
}, | ||
"complexity": { | ||
"useLiteralKeys": "off" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const { generateFieldMask, applyFieldMask } = require('./lib/fieldmask'); | ||
const { generateFieldMask, applyFieldMask } = require('./lib/fieldmask') | ||
|
||
module.exports.generateFieldMask = generateFieldMask; | ||
module.exports.applyFieldMask = applyFieldMask; | ||
module.exports.generateFieldMask = generateFieldMask | ||
module.exports.applyFieldMask = applyFieldMask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
function escape(propertyName) { | ||
return propertyName.replace(/\\/g, '\\\\').replace(/\./g, '\\.'); | ||
function escapeProperty(propertyName) { | ||
return propertyName.replace(/\\/g, '\\\\').replace(/\./g, '\\.') | ||
} | ||
|
||
function unescapeAndSplit(originalPath) { | ||
const properties = []; | ||
let path = originalPath; | ||
let i = path.indexOf('.'); | ||
const properties = [] | ||
let path = originalPath | ||
let i = path.indexOf('.') | ||
while (i >= 0) { | ||
if (isEscapedDot(path, i)) { | ||
path = unescapeFirstDotChar(path); | ||
path = unescapeFirstDotChar(path) | ||
// Find the index of the first dot AFTER the one we just unescaped | ||
i = path.indexOf('.', i); | ||
i = path.indexOf('.', i) | ||
} else { | ||
const firstProperty = path.substring(0, i); | ||
properties.push(unescapeEscapeChars(firstProperty)); | ||
path = path.substring(i + 1); | ||
i = path.indexOf('.'); | ||
const firstProperty = path.substring(0, i) | ||
properties.push(unescapeEscapeChars(firstProperty)) | ||
path = path.substring(i + 1) | ||
i = path.indexOf('.') | ||
} | ||
} | ||
|
||
properties.push(unescapeEscapeChars(path)); | ||
return properties; | ||
properties.push(unescapeEscapeChars(path)) | ||
return properties | ||
} | ||
|
||
function unescapeFirstDotChar(str) { | ||
return str.replace('\\.', '.'); | ||
return str.replace('\\.', '.') | ||
} | ||
|
||
function unescapeEscapeChars(str) { | ||
return str.replace(/\\\\/g, '\\'); | ||
return str.replace(/\\\\/g, '\\') | ||
} | ||
|
||
function isEscapedDot(path, i) { | ||
let counter = 0; | ||
let counter = 0 | ||
while (path.substring(i - 1, i) === '\\') { | ||
counter++; | ||
i--; | ||
counter++ | ||
i-- | ||
} | ||
|
||
return counter % 2 === 1; | ||
return counter % 2 === 1 | ||
} | ||
|
||
module.exports = { escape, unescapeAndSplit }; | ||
module.exports = { escapeProperty, unescapeAndSplit } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
"coveralls": "nyc report --reporter=lcov", | ||
"test": "mocha ./test", | ||
"test:coverage": "nyc npm test", | ||
"lint": "eslint .", | ||
"lint": "npx @biomejs/[email protected] lint index.js lib test biome.json", | ||
"lint:fix": "npx @biomejs/[email protected] check --apply index.js lib test biome.json", | ||
"prettier": "prettier --write \"{lib,test}/**/*.{js,ts}\"" | ||
}, | ||
"repository": { | ||
|
@@ -36,9 +37,6 @@ | |
}, | ||
"devDependencies": { | ||
"chai": "^4.3.7", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-prettier": "^3.4.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^12.0.2", | ||
"prettier": "^2.2.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,60 @@ | ||
const { assert } = require('chai'); | ||
const { escape, unescapeAndSplit } = require('../lib/escaping'); | ||
const { assert } = require('chai') | ||
const { escapeProperty, unescapeAndSplit } = require('../lib/escaping') | ||
|
||
describe('Escaping', () => { | ||
describe('escape', () => { | ||
it('should return property name as is when it does not contain special characters', () => { | ||
assert.equal(escape('foo'), 'foo'); | ||
}); | ||
assert.equal(escapeProperty('foo'), 'foo') | ||
}) | ||
|
||
it('should escape dots in the property name', () => { | ||
assert.equal(escape('foo.bar'), 'foo\\.bar'); | ||
}); | ||
assert.equal(escapeProperty('foo.bar'), 'foo\\.bar') | ||
}) | ||
|
||
it('should escape multiple dots in the property name', () => { | ||
assert.equal(escape('foo.bar.baz.'), 'foo\\.bar\\.baz\\.'); | ||
}); | ||
assert.equal(escapeProperty('foo.bar.baz.'), 'foo\\.bar\\.baz\\.') | ||
}) | ||
|
||
it('should escape the escape char', () => { | ||
assert.equal(escape('foo\\bar'), 'foo\\\\bar'); | ||
}); | ||
assert.equal(escapeProperty('foo\\bar'), 'foo\\\\bar') | ||
}) | ||
|
||
it('should escape the escape char when containing with dots', () => { | ||
assert.equal(escape('foo\\.bar'), 'foo\\\\\\.bar'); | ||
}); | ||
}); | ||
assert.equal(escapeProperty('foo\\.bar'), 'foo\\\\\\.bar') | ||
}) | ||
}) | ||
|
||
describe('unescapeAndSplit', () => { | ||
it('should array with single element when path is for a single property', () => { | ||
assert.deepEqual(unescapeAndSplit('foo'), ['foo']); | ||
}); | ||
assert.deepEqual(unescapeAndSplit('foo'), ['foo']) | ||
}) | ||
|
||
it('should return an array of names split by dot', () => { | ||
assert.deepEqual(unescapeAndSplit('foo.bar.baz'), ['foo', 'bar', 'baz']); | ||
}); | ||
assert.deepEqual(unescapeAndSplit('foo.bar.baz'), ['foo', 'bar', 'baz']) | ||
}) | ||
|
||
it('should unescape escaped dots', () => { | ||
assert.deepEqual(unescapeAndSplit('foo\\.bar'), ['foo.bar']); | ||
}); | ||
assert.deepEqual(unescapeAndSplit('foo\\.bar'), ['foo.bar']) | ||
}) | ||
|
||
it('should return an array of names split by dot with respect to escaped dots', () => { | ||
assert.deepEqual(unescapeAndSplit('foo\\.bar\\.baz.baf'), ['foo.bar.baz', 'baf']); | ||
}); | ||
assert.deepEqual(unescapeAndSplit('foo\\.bar\\.baz.baf'), ['foo.bar.baz', 'baf']) | ||
}) | ||
|
||
it('should handle trailing escaped dot correctly', () => { | ||
assert.deepEqual(unescapeAndSplit('foo\\..baz'), ['foo.', 'baz']); | ||
}); | ||
assert.deepEqual(unescapeAndSplit('foo\\..baz'), ['foo.', 'baz']) | ||
}) | ||
|
||
it('should handle escape char correctly', () => { | ||
assert.deepEqual(unescapeAndSplit('foo\\\\.baz'), ['foo\\', 'baz']); | ||
}); | ||
assert.deepEqual(unescapeAndSplit('foo\\\\.baz'), ['foo\\', 'baz']) | ||
}) | ||
|
||
it('should handle escape char with dot correctly', () => { | ||
assert.deepEqual(unescapeAndSplit('foo\\\\\\..baz'), ['foo\\.', 'baz']); | ||
}); | ||
assert.deepEqual(unescapeAndSplit('foo\\\\\\..baz'), ['foo\\.', 'baz']) | ||
}) | ||
|
||
it('should play well with escape function results', () => { | ||
assert.deepEqual(unescapeAndSplit(escape('foo\\.bar')), ['foo\\.bar']); | ||
}); | ||
}); | ||
}); | ||
assert.deepEqual(unescapeAndSplit(escapeProperty('foo\\.bar')), ['foo\\.bar']) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.