I'm trying to add a redirect that redirects from "node/1234" to "magazines/Epilepsy Today" I get the following error:

The redirect path magazines/Epilepsy Today is not valid.

If I try to add "magazines/Epilepsy%20Today" it works but then double encodes the % giving %2520.

As a quick way of solving this I manually edited the row in the database to add the space in which works.

Comments

trante’s picture

@digital006 hello,
i have such an error: http://drupal.org/node/1448706
and couldn't find a solution..
to reproduce can you please create a new node with non-ASCII characters and then change its alias
and check whether old alias goes to non-ASCII aliased node?

jaydub’s picture

StatusFileSize
new632 bytes

The issue here is that in fact a URL with spaces is not a 'valid' URL (to be valid it does need to be encoded). The add redirect form runs validation on the redirect field and tests the path with the function valid_url() which is what is causing the failure here. I'm not sure if this could cause undesirable side effects but one could perhaps add in a call to drupal_encode_path() before the valid_url() test is run.

attaching a patch which at least fixes the case above. The result is the redirect string being stored in the DB with the encoded space ('%20') which seems to be the desired result anyway.

jaydub’s picture

Status: Active » Needs review
James A’s picture

I'm also getting this issue with spaces in the path on version 7.x-1.0-rc1. Did you include the patch above in rc1 or is there a reason why it was left out?

Thanks for your help in advance.

TimG1’s picture

Hi All,

I tried this and it's not working the way I'd like it to. Yes, it converts spaces to %20 but I would like to save with the space, not encoded...exactly as typed.

Here's my use case. I have a list of faculty. I have a view showing all the faculty. There are different types of faculty. The URLs changed and I would like "example.com/adjunct-faculty" to redirect to "example.com/people/Adjunct Faculty". NOT "example.com/people/Adjunct%20Faculty". example.com/people is a view that will take the argument and using the "overwrite title" feature will overwrite the title of the page. Since there are no faculty tagged with "Adjunct%20Faculty" My view now shows "Adjunct%20Faculty" as the page title instead of "Adjunct Faculty" and the no results found message.

Thanks for reading,
-Tim

TimG1’s picture

Hi again,

Just learned that if I use "example.com/people/Adjunct-Faculty" that will get changed to "Adjunct Faculty" and works fine. So, just replace spaces with - and it works.

Thanks again,
-Tim

jwilson3’s picture

jwilson3’s picture

Title: Unable to add to alias with space in. » Add Redirect form breaks URLs containing spaces or %20

Lets clarify the issue title; these aren't aliases, but redirects.

wizonesolutions’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
StatusFileSize
new673 bytes

The patch indeed encodes URLs properly, but it doesn't fix the re-encoding issue when the redirect is actually passed to url(). It kind of needs to be stored unencoded in the database. This might be another issue.

In any case, here's a re-rolled version of this patch for now.

wizonesolutions’s picture

StatusFileSize
new671 bytes

Previous patch contained evil whitespace.

msharp.chi’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc1
StatusFileSize
new1.11 KB

I tried those patches, but the issue I have with them is that it introduces a double-encoding error i.e. save the url once and spaces are converted to %20. Save it twice and you get %2520 and so on.

The patch I've added separates the validation of the value from making sure it looks right. This ensures that the url is saved with spaces so it looks right, but validated with the appropriate encoding to make sure it validates correctly.

Status: Needs review » Needs work

The last submitted patch, redirect-space-fix.patch, failed testing.

javiereduardo’s picture

Status: Needs review » Needs work

patch #11 works. Thanks! (drupal 7.22 - redirect 7.x-1.0-rc1+4-dev) (I patched editing directly the file)

javiereduardo’s picture

Status: Needs work » Needs review

#11: redirect-space-fix.patch queued for re-testing.

The last submitted patch, redirect-space-fix.patch, failed testing.

The last submitted patch, redirect-space-fix.patch, failed testing.

gumdal’s picture

I had the same issue. But it could be solved.

What I was trying to do is to add the following URL in the Source / From field:
http://www.indiansnakes.org/Snakedatabase/Kraits/common_krait/common%20krait.html

But instead I had to add the following URL:
http://www.indiansnakes.org/Snakedatabase/Kraits/common_krait/common krait.html

If you include the blank space in the source URL, Redirect module will automatically encode it with %20. If you replace the space and provide %20, Redirect module will encode it as %2520

Reuben Unruh’s picture

StatusFileSize
new1.07 KB

Patch from #11 with file paths from within the module instead of from from Drupal root.

Reuben Unruh’s picture

Status: Needs work » Needs review
leewillis77’s picture

Hi Reuben,

In your code shouldn't the check:

$testvalue != '<front>'

be run against $value, not $testvalue?

pere orga’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev
Issue summary: View changes
Status: Needs review » Needs work

I agree

leewillis77’s picture

Status: Needs work » Needs review
StatusFileSize
new790 bytes

The revised patch contains the change I suggested.

pere orga’s picture

leewillis77’s picture

Looks so - I've added a note and linked the issues.

summit’s picture

Hi,
I implemented #22 patch. Am I ok for now?
greetings,
Martijn

tjmoyer’s picture

I'm not sure that patch is the right way to handle this. Drupal already encodes the URL when delivering the page or file, as evidenced by the fact that an encoded URL added to the redirect table in the database gets re-encoded when attempting to deliver it.

And we don't want to avoid a check for whether a file exists or not.

Instead, I purpose that we decode the URL that is submitted so redirect saves that, and the Drupal will encode it when it's needed. Here's my patch.

This seems to work for me. Does anyone see any potential issues with this?

tjmoyer’s picture

Here's a new patch that includes url decoding for the from field, as well.

summit’s picture

Hi @tjmoyer, I implemented your patch and until now its ok.
greetings, Martijn

srclarkx’s picture

This doesn't solve the problem of encoded characters in the query string. It only fixes the part before the '?' .

bennybobw’s picture

The patch in #27 will break urls where there is no drupal_get_normal_path. E.g. if I have a views url set up as workshops/% and I want to redirect ed101 -> workshop/Education%20101, drupal_get_normal_path will return 'workshop/Education 101', which fails valid_url because you can't have an unencoded space in the url.

cafuego’s picture

You can work around this problem by redirecting to an external URL, which causes Drupal to *not* double encode the special characters.

For example.com:

Fails: someuri -> sites/default/files/some file.pdf
Fails: someuri -> sites/default/files/some%20file.pdf
Works: someuri -> http://example.com/sites/default/files/some%20file.pdf
chris matthews’s picture

Status: Needs review » Needs work
bkosborne’s picture

I observe this issue in Drupal 8 version of Redirect as well. I created a separate bug report for that.

wylbur’s picture

Status: Needs work » Closed (duplicate)

Closing this as Outdated as Drupal 7 is EOL.