W3C home > Mailing lists > Public > public-swd-wg@w3.org > March 2008

ISSUE-98: URI escaping in SPARQL query in Recipe 6

From: SWD Issue Tracker <dean+cgi@w3.org>
Date: Sun, 16 Mar 2008 11:50:25 +0000 (GMT)
To: public-swd-wg@w3.org,public-rdf-in-xhtml-tf@w3.org
Message-Id: <20080316115025.75C096B62C@tibor.w3.org>

ISSUE-98: URI escaping in SPARQL query in Recipe 6


Raised by: Diego Berrueta
On product: Recipes

Escape sequences in URIs (such as %20 for whitespaces) must be double-escaped to
build a SPARQL query in the implementation of Recipe 6, pattern 2. The issue and
a potential solution were raised by Josh Tauberer (2008-01-20):

I ran into a problem when I created some URIs with %20's in them, 
because the redirect would need to double-escape the %20's when they are 
put into the query string.

After some chin-scratching I found out that mod_rewrite could be used to 
do a proper redirect, and I've documented it here:


There's more explanation in the link, but the short story is putting 
into the main httpd.conf:

   RewriteMap esc int:escape

and then into .htaccess:

   RewriteEngine on
   RewriteBase "/"
   RewriteRule ^(rdf/.*) http://%{HTTP_HOST}/sparql?   (..all one line..)
               query=DESCRIBE+<http://%{HTTP_HOST}/${esc:$1}> [R]


# When we get URIs with %20s or other escaped characters in them,
# a simple RedirectMatch won't do because in the query string
# DESCRIBE query, the escaped characters will be unescaped at
# some point during processing. So this is bad:
# RedirectMatch 303 (/rdf/.*)
# Instead, we need to double-escape the characters: The percent
# signs should ultimately be escaped so the processor gets back
# the original escaping when unescaping is applied.
# To do this, we need to use mod_rewrite. However, mod_rewrite is
# operating on the unescaped URI, so we need the 'escape' mapping
# function, which needs to be activated in httpd.conf with:
#     RewriteMap esc int:escape
# The rewrite rule below re-escapes the unescaped URI (getting back
# the problematic URL we started with), and then mod_rewrite
# escapes it again when it sends the redirect, finally achieving
# the double-escape.

RewriteEngine on
RewriteBase "/"
RewriteRule ^(rdf/.*)
http://%{HTTP_HOST}/sparql?query=DESCRIBE+<http://%{HTTP_HOST}/${esc:$1}> [R]

Source: http://rdfabout.com/demo/census/htaccess.txt
Received on Sunday, 16 March 2008 11:50:55 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:31:50 UTC