user903589
user903589

Reputation:

How to uri-encode unicode strings in Racket

the following code gives me an error:

(uri-encode "Kidô senkan Nadeshiko")

which is,

vector-ref: index is out of range
  index: 244
  valid range: [0, 127]
  vector: '#("%00" "%01" "%02" "%03" "%04" "%05" "%06" "%07" "%08" "%09" "%0A" "%0B" "%0C" "%0D" "%0E" "%0F" "%10" "%11" "%12" "%13" "%...
  context...:
   /usr/lib/racket/collects/net/uri-codec.rkt:197:6: for-loop
   /usr/lib/racket/collects/net/uri-codec.rkt:195:0: encode
   /usr/lib/racket/collects/racket/private/misc.rkt:87:7

I guess uri-encode and uri-decode only support ASCII which I can infer from the source of some tests, here

So my question is, is there a library on github or elsewhere that will uri encode unicode strings properly? Or do I have to roll my own?

Upvotes: 3

Views: 209

Answers (1)

Óscar López
Óscar López

Reputation: 235984

It might have something to do with the way you're running the program, or the version of Racket in use. I tested this in Racket 5.2.1 and it works for me:

#lang racket
(require net/uri-codec)

(uri-encode "Kidô senkan Nadeshiko")
=> "Kid%C3%B4%20senkan%20Nadeshiko"

Upvotes: 1

Related Questions