Link url field misinterprets IO lists

17 views
Skip to first unread message

Jeremy Raymond

unread,
Dec 19, 2011, 9:24:32 PM12/19/11
to nitro...@googlegroups.com
I've noticed if I use an IO list as the value for the link url field it comes out backwards and space separated. For example:

    #link{text = "Click here!", url = ["/root", "?param=", "value"]}

renders as

<a href="value ?param= /root" ...>Click here!</a>

Is this a known issue? Something I can do about it? My nitrogen_core version is 02713af5b8 (from around Sep 21st 2011).

Jesse Gumm

unread,
Dec 19, 2011, 9:40:37 PM12/19/11
to nitro...@googlegroups.com
Interesting. I was unaware of this. I guess I hadn't tried using an
iolist in the url field.

It appears the culprit is wf_convert:to_string_lists, which traverses
the list and reverses it. The easy fix is just to flatten the list in
element_link.

I've pushed a fix to mainline.

https://github.com/nitrogen/nitrogen_core/commit/2591d3d6e5e507f155db11531713a7206a85ee97

Thanks for the heads up :)

-Jesse

> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nitrogenweb/-/-0ngMinP3KIJ.
> To post to this group, send email to nitro...@googlegroups.com.
> To unsubscribe from this group, send email to
> nitrogenweb...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nitrogenweb?hl=en.

--
Jesse Gumm
Sigma Star Systems
414.940.4866
gu...@sigma-star.com
http://www.sigma-star.com

Jeremy Raymond

unread,
Dec 19, 2011, 10:41:58 PM12/19/11
to nitro...@googlegroups.com
Thanks for the quick fix.

Are lists (string()) the nominal Nitrogen data type? In general things will be more performant if I use strings instead of IO lists or binaries? I came across this issue trying to optimize some of my own code. I had been converting data into lists myself, but thought things may perform better if I just used IO lists instead (using a mix of strings and binaries as is my native data).

Jesse Gumm

unread,
Dec 19, 2011, 11:11:19 PM12/19/11
to nitro...@googlegroups.com
Generally speaking, yeah, lists are the usual data type in Nitrogen,
despite their performance issues.

But most things should work fine as iolists, particularly the body and
text fields. The URL field you mentioned is one of the first I've
come across where it acts seemingly unpredictable. As far as I could
tell, it was treating it kind of like the "class" field, where the
order of the classes is irrelevant.

On more looking though, it looks like it might be an oversight to in
the text fields allowing binaries the way they do, as they won't
convert text inside binaries (ie, converting < to &lt; won't happen in
binaries provided to the text fields with html_encode=true).

I should probably push a fix out there to convert them to lists (first
so that they'll convert properly).

That said, I haven't run any kind of benchmarks comparing the use of
iolists, lists, and binaries within nitrogen.

-Jesse

> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/nitrogenweb/-/X7giiT_8VmQJ.

Jeremy Raymond

unread,
Dec 20, 2011, 7:25:49 AM12/20/11
to nitro...@googlegroups.com
Okay thanks for the info.

--
Jeremy

Reply all
Reply to author
Forward
0 new messages