[e-lang] uriGetter encoding

Thomas Leonard tal at it-innovation.soton.ac.uk
Tue Jun 29 02:52:25 PDT 2010


On Mon, 2010-06-28 at 09:14 -0700, Kevin Reid wrote:
> On Jun 28, 2010, at 6:12, Thomas Leonard wrote:
> 
> > Well, I like it. I've used separate types for encoding strings before
> > and it works well to prevent subtle escaping bugs. I assume there  
> > would
> > be a guard for methods that need an encoded string? e.g.
> >
> > ? def encoded := "a b" :URIFragment
> > # value: URIFragment("a%20b")
> >
> > ? encoded :String
> > # value: "a b"
> >
> > I was a bit worried about backwards compatibility, but maybe the
> > coercion fixes that. Or, we could use the syntax version to turn it  
> > on.
> > Coercing to a String and back would be slightly lossy (using your
> > example of %26 = "&"). Is that OK?
> 
> No, it would be merely a label: coercion to a String would preserve  
> the characters.

Does that solve the problem? Whoever writes the file/directory object
won't be thinking about URIs, so the signature will be:

def directory {
  to get(name :String) :File
}

If someone else now decides to wrap that up as a uriGetter, the escaping
should work correctly, e.g.

def space1 := directory[" "]

def <mydir> := directory
def space2 := <mydir:%20>

space1 == space2


It seems a bit hacky if the author of the directory object is expected
to do something like this:

def directory {
  to get(maybeEncodedName :any) :File {
    def name := switch (maybeEncodedName) {
      match uri :URIEncoded { # must come first!
        uri.decode()
      }
      match s :String {
        s
      }
    }
    ...
  }
}


-- 
Dr Thomas Leonard
IT Innovation Centre
2 Venture Road
Southampton
Hampshire SO16 7NP

Tel: +44 0 23 8076 0834
Fax: +44 0 23 8076 0833
mailto:tal at it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk 



More information about the e-lang mailing list