[Opa] Dom ID's and hashes

Anand Patil anand.prabhakar.patil at gmail.com
Thu Sep 22 12:09:50 EDT 2011


I put this on the github issues page at
https://github.com/MLstate/opalang/issues/12 , seems like the civilized way
to do things.

Anand

On Thu, Sep 22, 2011 at 10:39 AM, Anand Patil <
anand.prabhakar.patil at gmail.com> wrote:

> Hi all,
>
>
> In the code below, setting id_char="a" works fine, whereas setting
> id_char="/" causes a silent failure:
>
> ---- start
>
> id_char = "/"
>
> hide_thing() =
>     Dom.hide(#{id_char})
>
> start =
>     | {path = [] ... } ->
>         Resource.styled_page("Hello.", ["/resources/css.css"],
>             <div id=#{id_char}> Hi. </div>
>             <div class="button" onclick={_ -> hide_thing()}>Hide the
> "Hi."</div>
>         )
>
>  server = Server.of_bundle([@static_include_directory("resources")])
> server = Server.simple_dispatch(start)
>
> ---- end
>
> I'm sure there are good reasons for forbidding some characters in dom ID's,
> but the silent failure makes it hard to figure out what's going on. It seems
> like Opa could catch most of these illegal ID labels at compile time, and
> give a proper runtime error for the rest.
>
>
> The way this came up is as follows. I've been labelling the id of the div
> that pertains to a particular record by the div of that record, for example
>
> badhash(x) =
>     Crypto.Base64.encode(Crypto.Hash.sha2(x))
>
> makediv(x, content) =
>     <div id=#{"div_of_{badhash(x)}"}> {content} </div>
>
> Once in a while that hash function made a hash with characters "+" or "/",
> which didn't work. To remedy that, I've made the following hash function,
> which always makes "URL- and ID- safe hashes". Would it be the type of thing
> that should go in the standard library?
>
> encode(x) =
>     enc = Crypto.Base64.encode(x)
>     rep1 = String.replace("/","s",enc)
>     String.replace("+","p",rep1)
>
> goodhash(x) : string =
>     encode(Crypto.Hash.sha2(OpaSerialize.serialize(x)))
>
>
> Cheers,
> Anand
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.owasp.org/pipermail/opa/attachments/20110922/763b3c89/attachment.html 


More information about the Opa mailing list