w2l bugfix: Always encode the characters \, { and } in URLs

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@119 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2011-07-25 08:47:49 +00:00
parent c565edaf57
commit a81298dc6f
2 changed files with 14 additions and 9 deletions

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2011-07-22) * Version 1.2 (2011-07-25)
* *
*/ */
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information // Version information
private static final String VERSION = "1.1.8"; private static final String VERSION = "1.1.8";
private static final String DATE = "2011-07-22"; private static final String DATE = "2011-07-25";
/** Return the Writer2LaTeX version in the form /** Return the Writer2LaTeX version in the form
* (major version).(minor version).(patch level)<br/> * (major version).(minor version).(patch level)<br/>

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2011-07-22) * Version 1.2 (2011-07-25)
* *
*/ */
@ -845,12 +845,12 @@ public class FieldConverter extends ConverterHelper {
if (ofr.getTextContent(node).trim().equals(sHref)) { if (ofr.getTextContent(node).trim().equals(sHref)) {
// The link text equals the url // The link text equals the url
ldp.append("\\url{") ldp.append("\\url{")
.append(oc.isInFootnote() ? escapeHref(sHref) : sHref) .append(escapeHref(sHref,oc.isInFootnote()))
.append("}"); .append("}");
} }
else { else {
ldp.append("\\href{") ldp.append("\\href{")
.append(oc.isInFootnote() ? escapeHref(sHref) : sHref) .append(escapeHref(sHref,oc.isInFootnote()))
.append("}{"); .append("}{");
// ignore text style (let hyperref.sty handle the decoration): // ignore text style (let hyperref.sty handle the decoration):
palette.getInlineCv().traverseInlineText(node,ldp,oc); palette.getInlineCv().traverseInlineText(node,ldp,oc);
@ -939,12 +939,17 @@ public class FieldConverter extends ConverterHelper {
return ", "+sName+"="+palette.getI18n().convert(sValue,false,palette.getMainContext().getLang()); return ", "+sName+"="+palette.getI18n().convert(sValue,false,palette.getMainContext().getLang());
} }
// For href within footnote, we have to escape the # and % characters // For the argument to a href, we have to escape or encode certain characters
private String escapeHref(String s) { private String escapeHref(String s, boolean bInFootnote) {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
for (int i=0; i<s.length(); i++) { for (int i=0; i<s.length(); i++) {
if (s.charAt(i)=='#') { buf.append("\\#"); } if (bInFootnote && s.charAt(i)=='#') { buf.append("\\#"); }
if (s.charAt(i)=='%') { buf.append("\\%"); } else if (bInFootnote && s.charAt(i)=='%') { buf.append("\\%"); }
// The following should not occur in an URL (see RFC1738), but just to be sure we encode them
else if (s.charAt(i)=='\\') { buf.append("\\%5C"); }
else if (s.charAt(i)=='{') { buf.append("\\%7B"); }
else if (s.charAt(i)=='}') { buf.append("\\%7D"); }
// hyperref.sty deals safely with other characters
else { buf.append(s.charAt(i)); } else { buf.append(s.charAt(i)); }
} }
return buf.toString(); return buf.toString();