Changeset 10472 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-06-24T01:43:16+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/InternetTags.java
r10469 r10472 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.net.IDN;7 import java.util.regex.Pattern;8 9 import org.openstreetmap.josm.Main;10 6 import org.openstreetmap.josm.data.osm.Node; 11 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 29 25 /** Error code for an invalid e-mail */ 30 26 public static final int INVALID_EMAIL = 3302; 31 32 private static final Pattern ASCII_PATTERN = Pattern.compile("^\\p{ASCII}+$");33 27 34 28 /** … … 86 80 */ 87 81 public TestError validateTag(OsmPrimitive p, String k, AbstractValidator validator, int code) { 88 TestError error = doValidateTag(p, k, null, validator, code); 89 if (error != null) { 90 // Workaround to https://issues.apache.org/jira/browse/VALIDATOR-290 91 // Apache Commons Validator 1.4.1-SNAPSHOT does not support yet IDN URLs 92 // To remove if it gets fixed on Apache side 93 String v = p.get(k); 94 if (!ASCII_PATTERN.matcher(v).matches()) { 95 try { 96 String protocol = ""; 97 if (v.contains("://")) { 98 protocol = v.substring(0, v.indexOf("://")+3); 99 } 100 String domain = !protocol.isEmpty() ? v.substring(protocol.length(), v.length()) : v; 101 String ending = ""; 102 if (domain.contains("/")) { 103 int idx = domain.indexOf('/'); 104 ending = domain.substring(idx, domain.length()); 105 domain = domain.substring(0, idx); 106 } 107 // Try to apply ToASCII algorithm 108 error = doValidateTag(p, k, protocol+IDN.toASCII(domain)+ending, validator, code); 109 } catch (IllegalArgumentException e) { 110 Main.trace(e); 111 error.setMessage(error.getMessage() + 112 tr(" URL cannot be converted to ASCII: {0}", e.getMessage())); 113 } 114 } 115 } 116 return error; 82 return doValidateTag(p, k, null, validator, code); 117 83 } 118 84
Note:
See TracChangeset
for help on using the changeset viewer.