Add email and website format validation

Simple validation following the HTML5 standard for emails as we don't
expect POIs to have convoluted email addresses. Only checks the
`website` and `email` tags as these are what iD currently supports with
fields.
This commit is contained in:
SilentSpike
2019-02-26 21:16:54 +00:00
committed by Quincy Morgan
parent d42cb7b790
commit 770cffe7de
4 changed files with 96 additions and 2 deletions

View File

@@ -1406,6 +1406,15 @@ en:
feature:
message: '{feature} lists Google as a data source'
reference: "Google products are proprietary and must not be used as references."
invalid_format:
title: Invalid Formatting
tip: Find features tagged with invalid value formatting
email:
message: '{feature} is tagged with an invalid email address'
reference: 'Email addresses must be of the form "local-part@domain".'
website:
message: '{feature} is tagged with an invalid website'
reference: 'Websites should start with a "http" or "https" scheme.'
missing_role:
title: Missing Roles
message: "{member} has no role within {relation}"
@@ -1921,4 +1930,4 @@ en:
wikidata:
identifier: "Identifier"
label: "Label"
description: "Description"
description: "Description"

12
dist/locales/en.json vendored
View File

@@ -1740,6 +1740,18 @@
"reference": "Google products are proprietary and must not be used as references."
}
},
"invalid_format": {
"title": "Invalid Formatting",
"tip": "Find features tagged with invalid value formatting",
"email": {
"message": "{feature} is tagged with an invalid email address",
"reference": "Email addresses must be of the form \"local-part@domain\"."
},
"website": {
"message": "{feature} is tagged with an invalid website",
"reference": "Websites should start with a \"http\" or \"https\" scheme."
}
},
"missing_role": {
"title": "Missing Roles",
"message": "{member} has no role within {relation}",

View File

@@ -6,10 +6,11 @@ export { validationFixmeTag } from './fixme_tag';
export { validationGenericName } from './generic_name';
export { validationImpossibleOneway } from './impossible_oneway';
export { validationIncompatibleSource } from './incompatible_source';
export { validationFormatting } from './invalid_format';
export { validationMaprules } from './maprules';
export { validationMissingRole } from './missing_role';
export { validationMissingTag } from './missing_tag';
export { validationOutdatedTags } from './outdated_tags';
export { validationPrivateData } from './private_data';
export { validationTagSuggestsArea } from './tag_suggests_area';
export { validationUnsquareWay } from './unsquare_way';
export { validationUnsquareWay } from './unsquare_way';

View File

@@ -0,0 +1,72 @@
import { t } from '../util/locale';
import { utilDisplayLabel } from '../util';
import { validationIssue } from '../core/validation';
export function validationFormatting() {
var type = 'invalid_format';
var validation = function(entity, context) {
var issues = [];
if (entity.tags.website) {
var valid_scheme = /^https?:\/\//i;
if (!valid_scheme.test(entity.tags.website)) {
issues.push(new validationIssue({
type: type,
subtype: 'website',
severity: 'warning',
message: function() {
var entity = context.hasEntity(this.entityIds[0]);
return entity ? t('issues.invalid_format.website.message', { feature: utilDisplayLabel(entity, context) }) : '';
},
reference: showReferenceWebsite,
entityIds: [entity.id]
}));
function showReferenceWebsite(selection) {
selection.selectAll('.issue-reference')
.data([0])
.enter()
.append('div')
.attr('class', 'issue-reference')
.text(t('issues.invalid_format.website.reference'));
}
}
}
if (entity.tags.email) {
// Same regex as used by HTML5 "email" inputs
// Emails in OSM are going to be official so they should be pretty simple
var valid_email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
if (!valid_email.test(entity.tags.email)) {
issues.push(new validationIssue({
type: type,
subtype: 'email',
severity: 'warning',
message: function() {
var entity = context.hasEntity(this.entityIds[0]);
return entity ? t('issues.invalid_format.email.message', { feature: utilDisplayLabel(entity, context) }) : '';
},
reference: showReferenceEmail,
entityIds: [entity.id]
}));
function showReferenceEmail(selection) {
selection.selectAll('.issue-reference')
.data([0])
.enter()
.append('div')
.attr('class', 'issue-reference')
.text(t('issues.invalid_format.email.reference'));
}
}
}
return issues;
};
validation.type = type;
return validation;
}