Opened 5 years ago

Closed 5 years ago

#14164 closed (fixed)

Automatic localization of numbers (L10N) in templates can cause invalid sitemap priorities

Reported by: dokterbob Owned by: nobody
Component: Internationalization Version: 1.2
Severity: Keywords: internationalization L10N sitemaps comma
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

When specifying priorities for a sitemap as a float (as is suggested by the official documentation) and USE_L10N = True, it can happen that requested sitemaps contain comma's in the priority values for items when the server detects certain locales. As the sitemaps specification requires a dot as a separator for float values this yields an invalid sitemap and has been confirmed to prohibit the indexing of certain sites.

The problem can be reproduced as follows:

  1. Make sure USE_L10N = True in settings.py.
  2. Create a Sitemap object with a priority and expose it somewhere in the URL space. (For example: priority = 0.5)
  3. Request the sitemap with a browser for which the decimal separator is something other than a dot. (This holds for many European locales.)
  4. Priority value should now be rendered wrongly. (For example: <priority>0,5</priority>)

As this problem is likely to occur for other situations where templates are used to render machine-parseable content, a structural solution should be in order.

Attachments (1)

14164_l10n_sitemaps.diff (3.9 KB) - added by vung 5 years ago.
Convert priority to str

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by dokterbob

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 in reply to: ↑ description Changed 5 years ago by dokterbob

One workaround that seems to do the job (for now) is to use a string value as the priority.

Changed 5 years ago by vung

Convert priority to str

comment:3 Changed 5 years ago by vung

  • Has patch set

comment:4 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [13644]) Fixed #14164 -- Ensure that sitemap priorities aren't rendered with localized numerical formats. Thanks to dokterbob for the report, and vung for the draft patch.

comment:5 Changed 5 years ago by russellm

(In [13646]) [1.2.X] Fixed #14164 -- Ensure that sitemap priorities aren't rendered with localized numerical formats. Thanks to dokterbob for the report, and vung for the draft patch.

Backport of r13644 from trunk.

comment:6 Changed 5 years ago by russellm

Getting sitemaps working is a priority, so I've committed the str() based patch. However, I've also opened #14181 to track the larger issue of 'delocalized' template rendering.

comment:7 Changed 5 years ago by palkeo

  • Patch needs improvement set
  • Resolution fixed deleted
  • Status changed from closed to reopened

I have applied this patch on my django installation because i had the same problem.

But there is another problem, only with the GenericSitemap : when the priority is not specified, i have « None » in the priority field of the sitemap.

I think you have to modify the lines 84 and 87 of the same file, and change the default value of priority, from None to .

comment:8 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from reopened to closed

@palkeo - I can't reproduce the behavior you describe. Defining a sitemap with no priority, or a priority that returns None (either as a class attribute or method) results in the priority field being omitted.

If you still think this is a bug, please open a *new* ticket with a specific test case -- preferably one using the newly provided test suite for the sitemaps app.

Note: See TracTickets for help on using tickets.
Back to Top