[armedbear-cvs] r13325 - trunk/abcl/src/org/armedbear/lisp

mevenson at common-lisp.net mevenson at common-lisp.net
Fri Jun 10 15:52:50 UTC 2011


Author: mevenson
Date: Fri Jun 10 08:52:50 2011
New Revision: 13325

Log:
Fix the URI decoding algorithim in Pathname.

Provide EXT:URI-DECODE and EXT:URI-ENCODE for access to the routines
used by Pathname.

Modified:
   trunk/abcl/src/org/armedbear/lisp/Pathname.java

Modified: trunk/abcl/src/org/armedbear/lisp/Pathname.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Pathname.java	Fri Jun 10 08:52:34 2011	(r13324)
+++ trunk/abcl/src/org/armedbear/lisp/Pathname.java	Fri Jun 10 08:52:50 2011	(r13325)
@@ -2429,14 +2429,52 @@
         Symbol.DEFAULT_PATHNAME_DEFAULTS.setSymbolValue(coerceToPathname(obj));
     }
 
+    
+    @DocString(name="uri-decode",
+               args="string => string",
+               doc="Decode percent escape sequences in the manner of URI encodings.")
+    private static final Primitive URI_DECODE = new pf_uri_decode();
+    private static final class pf_uri_decode extends Primitive {
+        pf_uri_decode() {
+            super("uri-decode", PACKAGE_EXT, true);
+        }
+        @Override
+        public LispObject execute(LispObject arg) {
+            if (!(arg instanceof AbstractString)) {
+                return error(new TypeError(arg, Symbol.STRING));
+            }
+            String result = uriDecode(((AbstractString)arg).toString());
+            return new SimpleString(result);
+        }
+    };
+
     static String uriDecode(String s) {
         try {
-            URI uri = new URI(null, null, null, s, null);
-            return uri.toASCIIString().substring(1);
+            URI uri = new URI("file://foo?" + s);
+            return uri.getQuery();
         } catch (URISyntaxException e) {}
         return null;  // Error
     }
 
+
+    @DocString(name="uri-encode",
+               args="string => string",
+               doc="Encode percent escape sequences in the manner of URI encodings.")
+    private static final Primitive URI_ENCODE = new pf_uri_encode();
+    private static final class pf_uri_encode extends Primitive {
+        pf_uri_encode() {
+            super("uri-encode", PACKAGE_EXT, true);
+        }
+        @Override
+        public LispObject execute(LispObject arg) {
+            if (!(arg instanceof AbstractString)) {
+                return error(new TypeError(arg, Symbol.STRING));
+            }
+            String result = uriEncode(((AbstractString)arg).toString());
+            return new SimpleString(result);
+        }
+    };
+
     static String uriEncode(String s) {
         // The constructor we use here only allows absolute paths, so
         // we manipulate the input and output correspondingly.




More information about the armedbear-cvs mailing list