diff --git a/modules/validations/suspicious_name.js b/modules/validations/suspicious_name.js index 369116becd..0a9bcd09d7 100644 --- a/modules/validations/suspicious_name.js +++ b/modules/validations/suspicious_name.js @@ -5,7 +5,7 @@ import { t, localizer } from '../core/localizer'; import { validationIssue, validationIssueFix } from '../core/validation'; -export function validationSuspiciousName() { +export function validationSuspiciousName(context) { const type = 'suspicious_name'; const keysToTestForGenericValues = [ 'aerialway', 'aeroway', 'amenity', 'building', 'craft', 'highway', @@ -45,9 +45,17 @@ export function validationSuspiciousName() { return false; } - function isGenericName(name, tags) { + /** @param {string} name @param {string} presetName */ + function nameMatchesPresetName(name, presetName) { + if (!presetName) return false; + + return name.toLowerCase() === presetName.toLowerCase(); + } + + /** @param {string} name @param {string} presetName */ + function isGenericName(name, tags, presetName) { name = name.toLowerCase(); - return nameMatchesRawTag(name, tags) || isGenericMatchInNsi(tags); + return nameMatchesRawTag(name, tags) || nameMatchesPresetName(name, presetName) || isGenericMatchInNsi(tags); } function makeGenericNameIssue(entityId, nameKey, genericName, langCode) { @@ -105,6 +113,8 @@ export function validationSuspiciousName() { let issues = []; + const presetName = presetManager.match(entity, context.graph()).name(); + for (let key in tags) { const m = key.match(/^name(?:(?::)([a-zA-Z_-]+))?$/); if (!m) continue; @@ -112,7 +122,7 @@ export function validationSuspiciousName() { const langCode = m.length >= 2 ? m[1] : null; const value = tags[key]; - if (isGenericName(value, tags)) { + if (isGenericName(value, tags, presetName)) { issues.provisional = _waitingForNsi; // retry later if we are waiting on NSI to finish loading issues.push(makeGenericNameIssue(entity.id, key, value, langCode)); } diff --git a/test/spec/validations/suspicious_name.js b/test/spec/validations/suspicious_name.js index f7696353da..6acb69390b 100644 --- a/test/spec/validations/suspicious_name.js +++ b/test/spec/validations/suspicious_name.js @@ -31,6 +31,10 @@ describe('iD.validations.suspicious_name', function () { iD.fileFetcher.cache().nsi_generics = { genericWords: ['^stores?$'] }; + iD.fileFetcher.cache().preset_presets = { + 'Velero': { tags: { craft: 'sailmaker' }, geometry: ['line'] }, + 'Constructor de barco': { tags: { craft: 'boatbuilder' }, geometry: ['line'] }, + }; }); after(function() { @@ -183,4 +187,29 @@ describe('iD.validations.suspicious_name', function () { done(); }, 20); }); + + it('flags feature with a name that matches the preset name', async () => { + await iD.presetManager.ensureLoaded(true); + createWay({ craft: 'sailmaker', 'name:ca': 'Velero' }); + const validator = iD.validationSuspiciousName(context); + + const issues = validate(validator); + expect(issues).to.have.lengthOf(1); + expect(issues[0].type).to.eql('suspicious_name'); + expect(issues[0].hash).to.eql('name:ca=Velero'); + }); + + it('flags feature with a name that matches the preset name and tag name', async () => { + await iD.presetManager.ensureLoaded(true); + createWay({ craft: 'boatbuilder', 'name:mi': 'boatbuilder', name: 'cOnStRuCtOr de barco' }); + const validator = iD.validationSuspiciousName(context); + + const issues = validate(validator); + expect(issues).to.have.lengthOf(2); + expect(issues[0].type).to.eql('suspicious_name'); + expect(issues[0].hash).to.eql('name:mi=boatbuilder'); + + expect(issues[1].type).to.eql('suspicious_name'); + expect(issues[1].hash).to.eql('name=cOnStRuCtOr de barco'); + }); });