diff --git a/data/core.yaml b/data/core.yaml index 7e61c9c20..8bb870156 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -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 diff --git a/dist/locales/en.json b/dist/locales/en.json index d5ad3be6f..26826ecb8 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -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." } }, diff --git a/modules/validations/invalid_format.js b/modules/validations/invalid_format.js index 37d9247b5..c51b35cb2 100644 --- a/modules/validations/invalid_format.js +++ b/modules/validations/invalid_format.js @@ -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')); } }