-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
invalid_format.js
100 lines (87 loc) 路 3.83 KB
/
invalid_format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { t } from '../core/localizer';
import { utilDisplayLabel } from '../util';
import { validationIssue } from '../core/validation';
export function validationFormatting() {
var type = 'invalid_format';
var validation = function(entity) {
var issues = [];
function isValidEmail(email) {
// Emails in OSM are going to be official so they should be pretty simple
// Using negated lists to better support all possible unicode characters (#6494)
var valid_email = /^[^\(\)\\,":;<>@\[\]]+@[^\(\)\\,":;<>@\[\]\.]+(?:\.[a-z0-9-]+)*$/i;
// An empty value is also acceptable
return (!email || valid_email.test(email));
}
function showReferenceEmail(selection) {
selection.selectAll('.issue-reference')
.data([0])
.enter()
.append('div')
.attr('class', 'issue-reference')
.call(t.append('issues.invalid_format.email.reference'));
}
/* see https://github.com/openstreetmap/iD/issues/6831#issuecomment-537121379
function isSchemePresent(url) {
var valid_scheme = /^https?:\/\//i;
return (!url || valid_scheme.test(url));
}
function showReferenceWebsite(selection) {
selection.selectAll('.issue-reference')
.data([0])
.enter()
.append('div')
.attr('class', 'issue-reference')
.call(t.append('issues.invalid_format.website.reference'));
}
if (entity.tags.website) {
// Multiple websites are possible
// If ever we support ES6, arrow functions make this nicer
var websites = entity.tags.website
.split(';')
.map(function(s) { return s.trim(); })
.filter(function(x) { return !isSchemePresent(x); });
if (websites.length) {
issues.push(new validationIssue({
type: type,
subtype: 'website',
severity: 'warning',
message: function(context) {
var entity = context.hasEntity(this.entityIds[0]);
return entity ? t.append('issues.invalid_format.website.message' + this.data,
{ feature: utilDisplayLabel(entity, context.graph()), site: websites.join(', ') }) : '';
},
reference: showReferenceWebsite,
entityIds: [entity.id],
hash: websites.join(),
data: (websites.length > 1) ? '_multi' : ''
}));
}
}*/
if (entity.tags.email) {
// Multiple emails are possible
var emails = entity.tags.email
.split(';')
.map(function(s) { return s.trim(); })
.filter(function(x) { return !isValidEmail(x); });
if (emails.length) {
issues.push(new validationIssue({
type: type,
subtype: 'email',
severity: 'warning',
message: function(context) {
var entity = context.hasEntity(this.entityIds[0]);
return entity ? t.append('issues.invalid_format.email.message' + this.data,
{ feature: utilDisplayLabel(entity, context.graph()), email: emails.join(', ') }) : '';
},
reference: showReferenceEmail,
entityIds: [entity.id],
hash: emails.join(),
data: (emails.length > 1) ? '_multi' : ''
}));
}
}
return issues;
};
validation.type = type;
return validation;
}