Skip to content

Commit

Permalink
[FIX] base_import: date(time) columns matching
Browse files Browse the repository at this point in the history
* actually pass the flags as flags in re.sub, passing re.IGNORECASE
  as *count* doesn't actually ignore case
* ensure the entire string is matched by the pattern, or we'll get
  shortest-matching-pattern which is *not* what the later strptime
  will do

closes #27925
  • Loading branch information
xmo-odoo committed Oct 18, 2018
1 parent 3df7757 commit 1ef791d
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions addons/base_import/models/base_import.py
Expand Up @@ -954,17 +954,12 @@ def to_re(pattern):
""" cut down version of TimeRE converting strptime patterns to regex
"""
pattern = re.sub(r'\s+', r'\\s+', pattern)
pattern = re.sub('%([a-z])', _replacer, pattern, re.IGNORECASE)

pattern = re.sub('%([a-z])', _replacer, pattern, flags=re.IGNORECASE)
pattern = '^' + pattern + '$'
return re.compile(pattern, re.IGNORECASE)
def _replacer(m):
return _P_TO_RE[m.group(1)]

def _joinre(patterns):
return '(' + '|'.join(
re.escape(p)
for p in sorted(patterns, key=len, reverse=True)
) + ')'
_P_TO_RE = {
'd': r"(3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
'H': r"(2[0-3]|[0-1]\d|\d)",
Expand Down

0 comments on commit 1ef791d

Please sign in to comment.