Opened 14 years ago

Closed 14 years ago

#14164 closed (fixed)

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

Reported by: Mathijs de Bruin 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: no UI/UX: no

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 14 years ago.
Convert priority to str

Download all attachments as: .zip

Change History (9)

comment:1 by Mathijs de Bruin, 14 years ago

in reply to:  description comment:2 by Mathijs de Bruin, 14 years ago

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

by vung, 14 years ago

Attachment: 14164_l10n_sitemaps.diff added

Convert priority to str

comment:3 by vung, 14 years ago

Has patch: set

comment:4 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

(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 by Russell Keith-Magee, 14 years ago

(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 by Russell Keith-Magee, 14 years ago

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 by palkeo, 14 years ago

Patch needs improvement: set
Resolution: fixed
Status: closedreopened

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 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: reopenedclosed

@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