patchSamizdat - Patches: patch #6171, lang in URL 0.2 [vs 080703-2] -...


You are not allowed to post comments on this tracker with your current authentication level.

patch #6171: lang in URL 0.2 [vs 080703-2] - allows the first preferred language to be set in the URL

Submitter:  Boud Roukema <boud>
Submitted:  Sun 26 Aug 2007 11:14:46 PM UTC
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  None Open/Closed:  Closed

Thu 09 Apr 2009 11:54:27 AM UTC, comment #3: 

This feature is provided in snapshot (Debian/experimental). Instead of a CGI parameter that could conflict with parameters of some controllers (e.g. the message preview problem mentioned by Boud), I've added language_prefix route rewriting plugin that allows to put language code as a prefix into the route part of the URL, e.g. http://samizdat-site/en/ or http://samizdat-site/en/blog/angdraug.

The prefix is valid for one page only, links from that page do not include it, so on folliwing any link the user will revert back to default behaviour.

Dmitry Borodaenko <angdraug>
Group administrator
Fri 15 Aug 2008 11:12:30 PM UTC, comment #2: 

BUG/FEATURE:  Version 0.2 against 080703-2 (maybe other cases too) has a side-effect: when previewing a message for publication, the request language temporarily becomes the language chosen for the message.

EXPLANATION: If i understand things correctly, the following is the explanation: Clicking on the preview button when publishing causes the preview method in message_controller to be called. The information sent to the server in the http header includes a parameter  lang=something.  Since the preview method is part of a new request, it uses this info whether or not it's in the URL or in the list of parameters from a submit form. After clicking confirm, the new request no longer has the hidden lang=something field sent to the samizdat server in the http server, so the request language reverts to what it was before.

DISCUSSION: Is this a bug or a feature? FEATURE: If someone is publishing something in some language, then s/he should normally know something about that language, even if s/he had not previously indicated this in his/her language preferences. Someone publishing something in a language that s/he does not really know should at least trust someone else in that language, and be able to consult that person in the case of any concerns. So is there a problem with temporarily switching to the chosen language? Probably not. It should also not be a problem switching back to the previous language afterwards, because multi-lingual people will not necessarily want to switch their preferred language to the language of that individual message. BUG: If someone feels that this is a bug, then one of the two 'lang' parameters could have its name changed. Probably changing the internal one in samizdat message_controller would make most sense in this case.

Personally, i see it as a feature. :)

Boud Roukema <boud>
Group Member
Tue 15 Jul 2008 02:00:20 AM UTC, comment #1: 

UPDATE for 080703-2. i'm not sure which makes more sense, for the lang in the URL to override the lang in the cookie or vice versa, though clearly, both should override the user's browser's accept-language settings.  My feeling is that a URL is more visible to the user than a cookie, so the URL lang=pl or whatever should override the cookie lang.

PATCH: attached.

(file #16121)

Boud Roukema <boud>
Group Member
Sun 26 Aug 2007 11:14:46 PM UTC, original submission:  


Some software packages (e.g. the version of mir which imports
rdf feeds) do not do Accept-Language http header negotiation
when importing feeds. It would to be able to help these faulty
software packages.


In request.rb, allow a URL parameter lang= to override the
environment variable and cookie settings in accept_language.

--- s070818/samizdat/lib/samizdat/engine/request.rb        2007-08-14 01:16:53.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/engine/request.rb        2007-08-27 00:41:19.027004488 +0200
@@ -170,6 +176,11 @@
     # lang cookie overrides Accept-Language
     lang = cookie('lang') and config_lang.include? lang and
       @accept_language.unshift lang
+    # lang in URL overrides above Accept-Language settings
+    l = self['lang'] and config_lang.include? l and
+      @accept_language.unshift l
     # use first language from config by default
     @accept_language.size == 0 and @accept_language = [config_lang[0]]
     # set interface language


Should there be any additional safety checks against the
content of the parameter? (E.g. in twiki there were some exploits
with people putting `some script` into the URL for searches)
Or is the config_lang.include? l  likely enough to remove
any chance of this sort of exploit? After all, sysadmin would
need to enter the dangerous code in the config file for this
to work, and it would need to be parsed unchanged when parsing
the config file, which seems unlikely when using odd characters.

Is this a problem of encouraging people to use URL parameters
instead of http header negotiation characters? i don't know
much about this.

i was not sure whether this should count as a bug or a patch -
this probably depends on whether we consider missing functionality
in other software to be something that we must handle or only
that we should or may handle it.

Boud Roukema <boud>
Group Member


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #16121:  080715-lang-in-URL-0.2 added by boud (740B - application/octet-stream)
file #13810:  070827-lang-in-URL-0.1 added by boud (641B - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by angdraug (Posted a comment)
  • -email is unavailable- added by boud (Submitted the item)

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-04-09 angdraug StatusWorks For Me Done
        Open/ClosedOpen Closed
    2008-07-16 boud Summarylang in URL 0.2 - allows the first preferred language to be set in the URL lang in URL 0.2 [vs 080703-2] - allows the first preferred language to be set in the URL
    2008-07-15 boud Attached File- Added 080715-lang-in-URL-0.2, #16121
        Summarylang in URL 0.1 - allows the first preferred language to be set in the URL lang in URL 0.2 - allows the first preferred language to be set in the URL
    2007-08-26 boud Attached File- Added 070827-lang-in-URL-0.1, #13810

    Back to the top

    Powered by Savane 3.13-8484.
    Corresponding source code