This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from mapbox/invalid-name
Comparator to flag invalid names of features
- Loading branch information
Showing
5 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
module.exports = invalidName; | ||
|
||
function invalidName(newVersion, oldVersion, callback) { | ||
|
||
// Not interested if there isn't a newVersion. | ||
if (!newVersion) return callback(null, {}); | ||
|
||
var properties = newVersion.properties; | ||
for (var key in properties) { | ||
var naughtyWords; | ||
|
||
// TODO: Having English as the default locale for now. | ||
if (key === 'name') { | ||
naughtyWords = require('naughty-words/en.json'); | ||
if (naughtyWords.indexOf(properties[key]) !== -1) return callback(null, {'result:invalid_name': true}); | ||
} else if (key.indexOf('name') === 0) { | ||
// Splitting 'name:ko' into ['name', 'ko'] | ||
var locale = key.split(':')[1]; | ||
|
||
// Name of the locale's naughty word file. | ||
var filename = 'naughty-words/' + locale + '.json'; | ||
|
||
try { | ||
naughtyWords = require(filename); | ||
if (naughtyWords.indexOf(properties[key]) !== -1) return callback(null, {'result:invalid_name': true}); | ||
} catch (error) { | ||
// TODO: naughty-words for the locale does not exist. Skip for now. | ||
} | ||
|
||
} | ||
} | ||
return callback(null, {}); | ||
} |
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
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,53 @@ | ||
{ | ||
"compareFunction": "invalid_name", | ||
"fixtures": [ | ||
{ | ||
"description": "Test feature with name tag but without profanity", | ||
"expectedResult": {}, | ||
"newVersion": { | ||
"type": "Feature", | ||
"properties": { | ||
"name": "Hello, world!" | ||
}, | ||
"geometry": null | ||
}, | ||
"oldVersion": null | ||
}, | ||
{ | ||
"description": "Test feature with profanity in name tag", | ||
"expectedResult": {"result:invalid_name": true}, | ||
"newVersion": { | ||
"type": "Feature", | ||
"properties": { | ||
"name": "xxx" | ||
}, | ||
"geometry": null | ||
}, | ||
"oldVersion": null | ||
}, | ||
{ | ||
"description": "Test feature with profanity in name:* tag", | ||
"expectedResult": {"result:invalid_name": true}, | ||
"newVersion": { | ||
"type": "Feature", | ||
"properties": { | ||
"name:ko": "강간" | ||
}, | ||
"geometry": null | ||
}, | ||
"oldVersion": null | ||
}, | ||
{ | ||
"description": "Test feature with profanity in name:* tag when naughty-words does not exist for the locale", | ||
"expectedResult": {}, | ||
"newVersion": { | ||
"type": "Feature", | ||
"properties": { | ||
"name:kn": "xxx" | ||
}, | ||
"geometry": null | ||
}, | ||
"oldVersion": null | ||
} | ||
] | ||
} |