Google Groups Home
Help | Sign in
Should symfony urlencode "/" character in URLs?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Marek  
View profile
 More options Mar 3, 7:49 am
From: Marek <m0k...@gmail.com>
Date: Mon, 3 Mar 2008 04:49:08 -0800 (PST)
Local: Mon, Mar 3 2008 7:49 am
Subject: Should symfony urlencode "/" character in URLs?
Hi devs,

Currenty symfony can create urls containing urlencoded slash (%2F),
which does not work for apache*, it throws right away 404 without even
looking at rewrite rules. This can be seen for example in sfSimpleCMS
plugin, where publich/unpublish/delete actions don't work for slugs
containing /

I don't think urlencoding of slash is necessery:
- symfony will receive decoded slash in either case (in case it's
encoded, AllowEncodedSlashes must be On)
- for parameters that might contain slash, "requirements: { paramname:
'.*'}" is required in routing configuration, and this will "eat" the
rest of the url, be it encoded or not.

I propose this change in controller/sfRouting.class.php - just before
return from generate() function, remove encoding of slash:

    $real_url = str_ireplace('%2F', '/', $real_url);

Any comments on this?

-- Marek

* It's possible to set AllowEncodedSlashes to On, but this setting is
only per server and vhost, and most hosts don't allow changing vhosts
sections.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian P. Christian  
View profile
 More options Mar 3, 7:56 am
From: "Ian P. Christian" <poo...@pookey.co.uk>
Date: Mon, 03 Mar 2008 12:56:43 +0000
Local: Mon, Mar 3 2008 7:56 am
Subject: Re: [symfony-devs] Should symfony urlencode "/" character in URLs?

Marek wrote:
> Hi devs,

> Currenty symfony can create urls containing urlencoded slash (%2F),
> which does not work for apache*, it throws right away 404 without even
> looking at rewrite rules. This can be seen for example in sfSimpleCMS
> plugin, where publich/unpublish/delete actions don't work for slugs
> containing /

See also:  [symfony-users] escaping escaping in URLs

--

Ian P. Christian ~ http://pookey.co.uk


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RickB  
View profile
 More options Mar 5, 6:44 am
From: RickB <rick.be...@gmail.com>
Date: Wed, 5 Mar 2008 03:44:26 -0800 (PST)
Local: Wed, Mar 5 2008 6:44 am
Subject: Re: Should symfony urlencode "/" character in URLs?
I think it's completely unnecessary to escape / characters in URLs. It
is only necessary to escape those characters that are not permissible
in URLs and those characters that have syntactic meaning (especially &
and =).

Rick

On Mar 3, 12:56 pm, "Ian P. Christian" <poo...@pookey.co.uk> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Coby  
View profile
 More options Mar 5, 9:28 am
From: Jacob Coby <jc...@portallabs.com>
Date: Wed, 5 Mar 2008 09:28:48 -0500
Local: Wed, Mar 5 2008 9:28 am
Subject: Re: [symfony-devs] Re: Should symfony urlencode "/" character in URLs?

On Mar 5, 2008, at 6:44 AM, RickB wrote:

> I think it's completely unnecessary to escape / characters in URLs. It
> is only necessary to escape those characters that are not permissible
> in URLs and those characters that have syntactic meaning (especially &
> and =).

If you're not going to fully escape URL parameters, how do you  
represent a slug (or some other value) in a URL with a / in it?

--
Jacob Coby
jc...@portallabs.com

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marek  
View profile
 More options Mar 5, 10:59 am
From: Marek <m0k...@gmail.com>
Date: Wed, 5 Mar 2008 07:59:41 -0800 (PST)
Local: Wed, Mar 5 2008 10:59 am
Subject: Re: Should symfony urlencode "/" character in URLs?
On 5. Mar., 15:28 h., Jacob Coby <jc...@portallabs.com> wrote:

> On Mar 5, 2008, at 6:44 AM, RickB wrote:

> > I think it's completely unnecessary to escape / characters in URLs. It
> > is only necessary to escape those characters that are not permissible
> > in URLs and those characters that have syntactic meaning (especially &
> > and =).

> If you're not going to fully escape URL parameters, how do you
> represent a slug (or some other value) in a URL with a / in it?

I'm talking about URL without query string, that's everything that
comes before the first "?".

Escaping / there makes apache serve 404 page for any request.

-- Marek


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Coby  
View profile
 More options Mar 5, 2:11 pm
From: Jacob Coby <jc...@portallabs.com>
Date: Wed, 5 Mar 2008 14:11:58 -0500
Local: Wed, Mar 5 2008 2:11 pm
Subject: Re: [symfony-devs] Re: Should symfony urlencode "/" character in URLs?

On Mar 5, 2008, at 10:59 AM, Marek wrote:

> I'm talking about URL without query string, that's everything that
> comes before the first "?".

Ahh, that makes more sense.  It definitely doesn't make sense to  
escape the path.

Jacob Coby
jc...@portallabs.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RickB  
View profile
 More options Mar 10, 6:48 am
From: RickB <rick.be...@gmail.com>
Date: Mon, 10 Mar 2008 03:48:42 -0700 (PDT)
Local: Mon, Mar 10 2008 6:48 am
Subject: Re: Should symfony urlencode "/" character in URLs?
On Mar 5, 2:28 pm, Jacob Coby <jc...@portallabs.com> wrote:

> If you're not going to fully escape URL parameters, how do you
> represent a slug (or some other value) in a URL with a / in it?

Ah! I understand your problem now - you're asking about a RESTful URL
with the request parameters converted to look like a long path.

E.g. /index.php?arg=my/slug would need to be converted to /arg/my/slug
but this raises a problem due to the / character being used to delimit
arguments and values.

The original case (/index.php?arg=my/slug) does not have a problem
with / characters in parameters - it's fully legit in URLs to do
this.  The problem only arises because of converting the request
parameters to look like a long URL, in which the / character takes on
a new meaning as the element delimiter (instead of ? and &).

I have some suggestions for what they're worth: either

1. escape the / as %2F
2. convert the / to \ for this purpose only (which would be a
reasonable thing to do - backslashes don't have any formal meaning in
URLs - however this is likely not to work in IE, which treats \ and /
as equivalent in spite of the standard definition of a URL).
3. don't use long URLs but go back to parameter lists (eg. /index.php?
arg=my/slug) when this is a problem.

I favour 3.
Rick


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francois Zaninotto  
View profile
 More options Mar 10, 9:08 am
From: "Francois Zaninotto" <francois.zanino...@symfony-project.com>
Date: Mon, 10 Mar 2008 14:08:05 +0100
Local: Mon, Mar 10 2008 9:08 am
Subject: Re: [symfony-devs] Re: Should symfony urlencode "/" character in URLs?

The problem is a common one. Symfony needs to URL-encode the parameters, so
that blank spaces in parameters do not make invalid URLs. For instance, it
is possible to call:

url_for('foo/bar/msg=hello, world!')

And you do need urlencoding for this to work. If you look at the way the
routing works, you will also see that it would complexify the code quite a
lot to allow users to define a per-parameter encoding option.

As for the / being turned into a %2F because of that, a common workaround is
to dedicate a special helper to build the links containing a path. Look at
what was done in sfSimpleCMSPlugin:

function link_to_with_path($text, $uri, $options = array())
{
  return str_replace('%2F', '/', link_to($text, $uri, $options));

}

Hope this helps,

françois

2008/3/10, RickB <rick.be...@gmail.com>:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
khaled  
View profile
 More options Apr 2, 4:42 am
From: khaled <khaledab...@gmail.com>
Date: Wed, 2 Apr 2008 01:42:51 -0700 (PDT)
Local: Wed, Apr 2 2008 4:42 am
Subject: Re: Should symfony urlencode "/" character in URLs?
hay man you can do this  this wrong  return str_replace('%2F', '/',
link_to($text, $uri, $options)); the right code is link_to('text','/
company/index?company_id='.$company->getId().'&tab=news'

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian P. Christian  
View profile
 More options Apr 2, 5:10 am
From: "Ian P. Christian" <poo...@pookey.co.uk>
Date: Wed, 02 Apr 2008 10:10:24 +0100
Local: Wed, Apr 2 2008 5:10 am
Subject: Re: [symfony-devs] Re: Should symfony urlencode "/" character in URLs?

khaled wrote:
> hay man you can do this  this wrong  return str_replace('%2F', '/',
> link_to($text, $uri, $options)); the right code is link_to('text','/
> company/index?company_id='.$company->getId().'&tab=news'

Do you realise who your post was addressing? ;)
That was Francois, of... symfony fame :P

Anyway, you're wrong, please read the whole thread before posting next
time.  To help you understand, the problem is when one of your params
contains a '/' itself

Kind Regards,

Ian


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google