Skip to content

Commit

Permalink
Check only hostname for URL sources
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromml authored and 1ec5 committed Mar 1, 2024
1 parent d3f48b1 commit fac20bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/validations/incompatible_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export function validationIncompatibleSource() {

return entitySources
.map(source => {
try {
const sourceURL = new URL(source);
source = sourceURL.hostname;
} catch (e) {
// Source string is not a url
}
const matchRule = incompatibleRules.find(rule => {
if (!rule.regex.test(source)) return false;
if (rule.exceptRegex && rule.exceptRegex.test(source)) return false;
Expand Down
16 changes: 16 additions & 0 deletions test/spec/validations/incompatible_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ describe('iD.validations.incompatible_source', function () {
expect(issue.entityIds[0]).to.eql('w-1');
});

it('flags way with incompatible URL source tag', function() {
createWay({ amenity: 'cafe', building: 'yes', name: 'Key Largo Café', source: 'https://www.google.com/maps'});
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('incompatible_source');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
});

it('ignores way with incompatible string outside of URL hostname', function() {
createWay({ amenity: 'cafe', building: 'yes', name: 'Key Largo Café', source: 'https://www.mercurynews.com/2019/10/03/new-office-tower-gets-underway-downtown-san-jose-google-adobe-tech/'});
var issues = validate();
expect(issues).to.have.lengthOf(0);
});

it('does not flag buildings in the google-africa-buildings dataset', function() {
createWay({ building: 'yes', source: 'esri/Google_Africa_Buildings' });
var issues = validate();
Expand Down

0 comments on commit fac20bd

Please sign in to comment.