Edgewall Software

Opened 8 years ago

Closed 8 years ago

#12408 closed defect (fixed)

ValueError: 'ru_' is not a valid locale identifier — at Version 2

Reported by: Ryan J Ollos Owned by: Jun Omae
Priority: normal Milestone: 1.0.11
Component: i18n Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fix crashing with an invalid locale identifier in Accept-Language header.

API Changes:
Internal Changes:

Description

From the logs:

[pid 28367 139730844534528] 2016-03-17 12:00:43,591 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/ticket/8537'">, referrer 'http://yandex.ru/clck/jsredir?from=yandex.ru%3Byandsearch%3Bweb%3B%3B&text=&etext=996._sIBbfoRyfFl628gfy4wb8GngehrMBwSC7CXRLWNRYhLLhpmx7EvaGcjjuYeFmQD14E3mFJcXk-h6CbBEc5UZw.12af3036e129fb6763dcaac9240205465df05f55&uuid=&state=PEtFfuTeVD5kpHnK9lio9bb4iM1VPfe4W5x0C0-qwflIRTTifi6VAA&data=UlNrNmk5WktYejR0eWJFYk1LdmtxcThQTlRjekdrTUhqM0hYOUk1WWk1MFQxTlNEQ2Y0MEdubmZQX3hEZUlqLWVfc09icFp2RlpZQUVtcGhDM0Vpd0xPWVhmNjh3cGI2NXE1QXdFS19TY3UwRTNDdmstNTh4dw&b64e=2&sign=1691792961b6803311f9eaac7e5df091&keyno=0&cst=AiuY0DBWFJ5fN_r-AEszk6SEig93GzDCaS29aZtj43HiwARcg1-ZnP3GkqslLqMCBROiauxpAhFxQAFGGxL9QLWGoizTj9Q45x3mrMMVrciO-2nx5H1PkKMlSG_cAP_flJ_E1rvun6a_FXbkEbnWPSRDB1qtBewcsI9fhVr_7kHD_8akdYRDOXBRTHI8R7guEYVGEAoF61jfoUDJ_cDi9w&ref=orjY4mGPRjk5boDnW0uvlpAgqs5Jg3qugxMaS29Lcl7Yi1edZebLv32-bNUmkn21e_S_nmQ7Y13nuQiIXRefh3OWfJA2t7yCtXkGqw-P9m7vzB1P2Nrm_4ReaOwCCXUjDWEM2NswOgxvcTQbcunhlPNBnKvOTPDX&l10n=ru&cts=1458212384800&mc=0'
Traceback (most recent call last):
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/main.py", line 607, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/main.py", line 256, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/ticket/web_ui.py", line 178, in process_request
    return self._process_ticket_request(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/ticket/web_ui.py", line 759, in _process_ticket_request
    chrome.add_jquery_ui(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/chrome.py", line 1396, in add_jquery_ui
    'first_week_day': get_first_week_day_jquery_ui(req),
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/util/datefmt.py", line 475, in get_first_week_day_jquery_ui
    l = Locale.parse(l)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/babel/core.py", line 252, in parse
    parts = parse_locale(identifier, sep=sep)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/babel/core.py", line 958, in parse_locale
    raise ValueError('%r is not a valid locale identifier' % identifier)
ValueError: 'ru_' is not a valid locale identifier

Change History (2)

comment:1 by Jun Omae, 8 years ago

Milestone: next-stable-1.0.x1.0.11
Owner: set to Jun Omae
Status: newassigned

Reproduced with the following.

$ curl --header "Accept-Language: ru-" http://localhost/timeline

I'll push this with unit tests.

  • trac/util/datefmt.py

    diff --git a/trac/util/datefmt.py b/trac/util/datefmt.py
    index d384fa6d2..afbd383b4 100644
    a b def get_first_week_day_jquery_ui(req):  
    472472                        if l.territory:
    473473                            locale = l
    474474                            break
    475                     except UnknownLocaleError:
     475                    except (UnknownLocaleError, ValueError):
    476476                        pass
    477477        if not locale.territory and locale.language in LOCALE_ALIASES:
    478478            locale = Locale.parse(LOCALE_ALIASES[locale.language])

comment:2 by Jun Omae, 8 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fixed in [14631] and merged to trunk in [14632].

Note: See TracTickets for help on using tickets.