Support » Plugin: Airpress » 404 when space/ in URL

  • Airpress will not return matches if there is a url encoded space in the filter field.

    Browsers automatically url encode spaces to %20 so if my Virtual Post match pattern is:
    ^things/([^/]+)/?$
    and my filter formula is
    {Thing Name} = ‘$1’

    when I request /things/thing%20one/
    I get a 404 error rather than the record with the Thing Name field of ‘thing one’

    How can I get AirPress to url-decode $1 in the regex before it does its filtering?

    thanks for your help

    saul

Viewing 4 replies - 1 through 4 (of 4 total)
  • Probably not the solution you’re looking for, but because of similar issues I match on a formula field called ‘slug’ rather than on the actual ‘Name’ field. In my case, I use the following formula to slug-ify record names:

    LOWER(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE({name},"/","-")," ","-"),"é","e"))

    In your case, you might want to do something along these lines:

    LOWER(SUBSTITUTE({name}," ","%20"))

    There are a number of standard URL-encoding substitutions, but you’re probably safer to include only the ones you need. The following are considered ‘reserved’ characters under RFC 3986 and must be encoded if included as part of a URL:

     !    #    $    &    '    (    )    *    +    ,    /
    %21  %23  %24  %26  %27  %28  %29  %2A  %2B  %2C  %2F

     :    ;    =    ?    @    [    ]
    %3A  %3B  %3D  %3F  %40  %5B  %5D

    That said, your web server and/or WordPress will almost certainly intercept ‘/’, ‘?’, and ‘&’, at least, before they get to you. [As you note, the space character should be encoded as ‘%20’ and the percent sign (‘%’) as ‘%25’. If you need to support the latter, it has to be handled in the most deeply nested SUBSTITUTE() call lest you end up with such things as ‘%2520’ for a space.]

    The following formula is overkill, but it will encode all reserved characters except ‘/’, ‘?’, and ‘&’, plus the space character and ‘%’. Again, I recommend you *not* use it but instead create only those substitutions for which you have a definite need.

    LOWER(
    	SUBSTITUTE(
    		SUBSTITUTE(
    			SUBSTITUTE(
    				SUBSTITUTE(
    					SUBSTITUTE(
    						SUBSTITUTE(
    							SUBSTITUTE(
    								SUBSTITUTE(
    									SUBSTITUTE(
    										SUBSTITUTE(
    											SUBSTITUTE(
    												SUBSTITUTE(
    													SUBSTITUTE(
    														SUBSTITUTE(
    															SUBSTITUTE(
    																SUBSTITUTE(
    																	SUBSTITUTE({name},"%","%25"),
    																" ","%20"),
    															"!","%21"),
    														"#","%23"),
    													"$","%24"),
    												"'","%27"),
    											"(","%28"),
    										")","%29"),
    									"*","%2A"),
    								"+","%2B"),
    							",","%2C"),
    						":","%3A"),
    					";","%3B"),
    				"=","%3D"),
    			"@","%40"),
    		"[","%5B"),
    	"]","%5D"))

    Maz

    • This reply was modified 3 years, 7 months ago by mazoola.
    • This reply was modified 3 years, 7 months ago by mazoola.
    • This reply was modified 3 years, 7 months ago by mazoola.
    Thread Starter saulcoz

    (@saulcoz)

    Thanks Maz,

    but I’m not sure where you are suggesting that I use that formula. The Filter by Formula input on the Virtual Posts config interface doesn’t let me set a formula with even one SUBSTITUTE.

    cheers

    saul

    Sorry; that was about the most disjointed message I can recall writing in a while.

    What I was suggesting was that you create an additional field called ‘slug’, perhaps, defined as a formula field using some variant of the ones I provided, and pre-encode your record {name}s. Then, modify your Virtual Posts to match on {slug} rather than {name}. That’s how I deal with a base loaded with names containing reserved or extended characters….

    Maz

    Thread Starter saulcoz

    (@saulcoz)

    Ah – now I understand what you meant. I hadn’t even thought about fixing it at the Airtable end.

    Anyway – I think I fixed it with a little PHP in WordPress

    
    function decode_request($req){
    	$req->request=urldecode($req->request);
    	return $req;
    }
    add_action( 'parse_request',"decode_request",1,1);
    

    thanks for your ideas though – it’s good to have options.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘404 when space/ in URL’ is closed to new replies.