Skip to content

Commit

Permalink
Item8924: added URL encoding to values passed via meta to JS. There a…
Browse files Browse the repository at this point in the history
…re two important changes here that need careful consideration. First, because foswiki.PREFERENCE values are now URL encoded, anything that bypasses foswiki.getPreference and uses foswiki.getMetaTag (or similar) to retrieve a preference value from EXPORTEDPREFERENCES needs to decode the value. Second, in order to support this I needed a proper URL encoding, but found that ENCODE doesn't provide one. After some detailed examination of the history of <br> encoding (which stretches back to a checkin in early 2001), I couldn't find any rational reason for it, other than sloppy coding. I have removed it, which means that newlines will now be encoded using the normal URL encoding. There's a chance this may impact a wiki application, but TBH I think it's the lesser of the evils to fix this poisonous legacy now. If people disagree, then the alternative is to add a type=uri that does a proper encoding.

git-svn-id: http://svn.foswiki.org/trunk@7694 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jun 8, 2010
1 parent f54647f commit 336175d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Expand Up @@ -60,6 +60,7 @@ if (foswiki.preferences === undefined) {
// Check for a preference passed in a meta tag (this is the classical method)
var metaVal = $("meta[name=foswiki."+key+"]").attr("content");
if (metaVal !== undefined) {
metaVal = unescape(metaVal);
// Cache it for future reference
foswiki.preferences[key] = metaVal;
return metaVal;
Expand Down
7 changes: 6 additions & 1 deletion core/lib/Foswiki/Macros/ENCODE.pm
Expand Up @@ -71,7 +71,12 @@ sub ENCODE {
return $text;
}
elsif ( $type =~ /^url$/i ) {
$text =~ s/\r*\n\r*/<br \/>/; # Legacy.
# This is legacy, stretching back to 2001. Checkin comment was:
# "Fixed URL encoding". At that time it related to the encoding of
# parameters to the "oops" script exclusively. I'm taking it out
# because I can't see any situation in which it might have been
# used in anger.
# $text =~ s/\r*\n\r*/<br \/>/;
return urlEncode($text);
}
elsif ( $type =~ /^(off|none)$/i ) {
Expand Down
9 changes: 5 additions & 4 deletions core/pub/System/JavascriptFiles/foswikilib_src.js
Expand Up @@ -45,7 +45,7 @@ foswiki.getMetaTag = function(inKey) {
for (var i = 0; i < head.length; i++) {
if (head[i].tagName != null &&
head[i].tagName.toUpperCase() == 'META') {
foswiki.metaTags[head[i].name] = head[i].content;
foswiki.metaTags[head[i].name] = unescape(head[i].content);
}
}
}
Expand Down Expand Up @@ -86,16 +86,17 @@ foswiki.getPreference = function(key, useServer) {
if (foswiki.preferences === undefined) {
foswiki.preferences = {};
}
foswiki.preferences[key] = metaVal;
foswiki.preferences[key] = unescape(metaVal);
return metaVal;
}

// Use AJAX to get a preference value from the server. This requires
// a lot of context information to be passed to the server, and a REST
// handler on the server, so has not been implemented yet.
if (useServer) {
window.alert("Trying to get preference '" + key + "' from server, but " +
"this feature is not implemented yet.");
window.alert("Trying to get preference '" + key
+ "' from server, but " +
"this feature is not implemented yet.");
}
return null;
};
Expand Down
2 changes: 1 addition & 1 deletion core/templates/foswiki.tmpl
Expand Up @@ -16,7 +16,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%LANG%" lang="%LANG%">%TMPL:END%

%TMPL:DEF{"meta:preferences"}%%FOREACH{"%EXPORTEDPREFERENCES%"
format="<meta name='foswiki.$topic' content='$percnt$topic$percnt' />"
format="<meta name=\"foswiki.$topic\" content=\"$percntENCODE{\"$percnt$topic$percnt\"}$percnt\" /><!--$topic-->"
separator="
"
}%
Expand Down

0 comments on commit 336175d

Please sign in to comment.