mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-13 04:44:50 +02:00
Fix email and website validation for list values
Also improved the UI message to be more clear for websites and simplify "is tagged with" to "has" which works in context.
This commit is contained in:
committed by
Quincy Morgan
parent
770cffe7de
commit
591e41f5ec
+4
-2
@@ -1410,10 +1410,12 @@ en:
|
||||
title: Invalid Formatting
|
||||
tip: Find features tagged with invalid value formatting
|
||||
email:
|
||||
message: '{feature} is tagged with an invalid email address'
|
||||
message: '{feature} has an invalid email address: {email}'
|
||||
message_multi: '{feature} has multiple invalid email addresses: {email}'
|
||||
reference: 'Email addresses must be of the form "local-part@domain".'
|
||||
website:
|
||||
message: '{feature} is tagged with an invalid website'
|
||||
message: '{feature} has a website with no scheme: {site}'
|
||||
message_multi: '{feature} has multiple websites with no scheme: {site}'
|
||||
reference: 'Websites should start with a "http" or "https" scheme.'
|
||||
missing_role:
|
||||
title: Missing Roles
|
||||
|
||||
Vendored
+4
-2
@@ -1744,11 +1744,13 @@
|
||||
"title": "Invalid Formatting",
|
||||
"tip": "Find features tagged with invalid value formatting",
|
||||
"email": {
|
||||
"message": "{feature} is tagged with an invalid email address",
|
||||
"message": "{feature} has an invalid email address: {email}",
|
||||
"message_multi": "{feature} has multiple invalid email addresses: {email}",
|
||||
"reference": "Email addresses must be of the form \"local-part@domain\"."
|
||||
},
|
||||
"website": {
|
||||
"message": "{feature} is tagged with an invalid website",
|
||||
"message": "{feature} has a website with no scheme: {site}",
|
||||
"message_multi": "{feature} has multiple websites with no scheme: {site}",
|
||||
"reference": "Websites should start with a \"http\" or \"https\" scheme."
|
||||
}
|
||||
},
|
||||
|
||||
@@ -7,59 +7,79 @@ export function validationFormatting() {
|
||||
|
||||
var validation = function(entity, context) {
|
||||
var issues = [];
|
||||
if (entity.tags.website) {
|
||||
var valid_scheme = /^https?:\/\//i;
|
||||
|
||||
if (!valid_scheme.test(entity.tags.website)) {
|
||||
function isInvalidEmail(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-]+)*$/;
|
||||
return !valid_email.test(email);
|
||||
}
|
||||
|
||||
function isSchemeMissing(url) {
|
||||
var valid_scheme = /^https?:\/\//i;
|
||||
return !valid_scheme.test(url);
|
||||
}
|
||||
|
||||
|
||||
if (entity.tags.website) {
|
||||
// Multiple websites are possible
|
||||
var websites = entity.tags.website.split(';').filter(isSchemeMissing);
|
||||
|
||||
if (websites.length) {
|
||||
var multi = (websites.length > 1) ? '_multi' : '';
|
||||
|
||||
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) }) : '';
|
||||
return entity ? t('issues.invalid_format.website.message' + multi, { feature: utilDisplayLabel(entity, context), site: websites.join(', ') }) : '';
|
||||
},
|
||||
reference: showReferenceWebsite,
|
||||
entityIds: [entity.id]
|
||||
entityIds: [entity.id],
|
||||
hash: websites.join()
|
||||
}));
|
||||
}
|
||||
|
||||
function showReferenceWebsite(selection) {
|
||||
selection.selectAll('.issue-reference')
|
||||
.data([0])
|
||||
.enter()
|
||||
.append('div')
|
||||
.attr('class', 'issue-reference')
|
||||
.text(t('issues.invalid_format.website.reference'));
|
||||
}
|
||||
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-]+)*$/;
|
||||
// Multiple emails are possible
|
||||
var emails = entity.tags.email.split(';').filter(isInvalidEmail);
|
||||
|
||||
if (emails.length) {
|
||||
var multi = (emails.length > 1) ? '_multi' : '';
|
||||
|
||||
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) }) : '';
|
||||
return entity ? t('issues.invalid_format.email.message' + multi, { feature: utilDisplayLabel(entity, context), email: emails.join(', ') }) : '';
|
||||
},
|
||||
reference: showReferenceEmail,
|
||||
entityIds: [entity.id]
|
||||
entityIds: [entity.id],
|
||||
hash: emails.join()
|
||||
}));
|
||||
}
|
||||
|
||||
function showReferenceEmail(selection) {
|
||||
selection.selectAll('.issue-reference')
|
||||
.data([0])
|
||||
.enter()
|
||||
.append('div')
|
||||
.attr('class', 'issue-reference')
|
||||
.text(t('issues.invalid_format.email.reference'));
|
||||
}
|
||||
function showReferenceEmail(selection) {
|
||||
selection.selectAll('.issue-reference')
|
||||
.data([0])
|
||||
.enter()
|
||||
.append('div')
|
||||
.attr('class', 'issue-reference')
|
||||
.text(t('issues.invalid_format.email.reference'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user