diff options
| author | Kempei Igarashi <kempe@iga-network.com> | 2020-03-12 18:36:08 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-12 18:36:08 +0900 |
| commit | 6bed086fd73fcdab0f6f112fb91ec908b5f52b85 (patch) | |
| tree | cdad4281a05a29c3f96e4d99e81e9dbaf8f6cb98 | |
| parent | 4d77c464bfcecb500514751e9dd816ec1d46451e (diff) | |
| download | rdflib-6bed086fd73fcdab0f6f112fb91ec908b5f52b85.tar.gz | |
Update is_valid_uri() for checking Unicode letter
is_valid_uri() checked only 'in' criteria so that it couldn't check URI which includes Unicode letter other than ASCII zone.
ex. http://ex.com/漢字 should be valid but not
Change: use unicodedata.category for checking Unicode Category, 'Lx' category is valid. If not, use same logic as before.
See: https://www.unicode.org/reports/tr44/#General_Category
| -rw-r--r-- | rdflib/term.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/rdflib/term.py b/rdflib/term.py index 3665ff22..5f06e95b 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -50,6 +50,7 @@ import xml.dom.minidom from datetime import date, time, datetime, timedelta from re import sub, compile from collections import defaultdict +from unicodedata import category from isodate import parse_time, parse_date, parse_datetime, Duration, parse_duration, duration_isoformat @@ -73,10 +74,11 @@ _invalid_uri_chars = '<>" {}|\\^`' def _is_valid_uri(uri): - for c in _invalid_uri_chars: - if c in uri: - return False - return True + """ + Verify invalid chars other than Unicode Letter (Category: Lx) + Ref: https://www.unicode.org/reports/tr44/#General_Category + """ + return all(map(lambda c: category(c).startswith('L') or not c in _invalid_uri_chars, uri)) _lang_tag_regex = compile('^[a-zA-Z]+(?:-[a-zA-Z0-9]+)*$') |
