< Erlyweb mailing list ~ bug: annoying double slash in function a/? when app root is
|Posted: Thu Jul 31, 2008 10:51 am
I went to investigate the problem and I found out a few things.
I found this problem in the release version 0.7.2, I haven't checked the
bleeding version yet. So beware! I might be doing something redundant.
First of all, my problem wasn't caused by not setting an app root. If
you don't set an app root, the erlyweb app will simply _not_work_.
The minimal setting for an app root is "/" (app-root-/). If you define
an app root from the appmods parameter in yaws.conf as "/", like this:
appmods = <"/", erlyweb> then that will have some nasty side-effects on
your browser when using a 'magic' component.
Side-effects? If a module has the magic property turned on,
(i.e. the component reuses erlyweb_controller and erlyweb_view) then all
the a_hrefs generated by the a/2 function in erlyweb_html will produce
[a href="//module/function/par0/.../parn"]text[/a], if one enters the
value of erlyweb:get_app_root function, which is entered as a parameter
to the a/2 function.
Notice the initial double slashes in the hyperlink expression. Most
browsers tend to interpret this strange addressing as
http://module/function/par0/.../parn ... This will in turn send your
browser to go to an existing website or not... where you did not intend
to go. I've tested on mozilla and opera.
I noticed this problem in erlyweb_view.et in the list/3 function.
Where a hyperlink "create new" is declared.
The solution could be quite simple. Don't set your app root to "/".
... or ... read on.
Subsequently I found a peculiar hack Yariv did on the
[case erlyweb:get_app_root(A) of
"/" -> "";
Root -> Root
The good thing about this is that it's a local hack that works. The bad
thing is that an erlyweb programmer would have to apply this same hack
where she wishes to uses the a/2 function where app-root-/ is also required.
This problem came to light because Yariv probably forgot to apply this
hack in the "create new" hyperlink (erlyweb_controller:list/3 and
*_view:list/1), which spurred me on to find the root cause.
First, remove Yariv's localized hack, just return
erlyweb:get_app_root(A) in the list, don't worry, this affects only the
list/3 function that enumerates the records of a table (magically).
Second, apply my patch.
I modified the join function to match for $/ and  (incl. or) or "" ,
and disregard them while inserting slashes to the first
parameter of the a/2 function. ($ is used to declare something as a
character type(?) in erlang comparable to C/C++'s '/')
|Back to top
All times are GMT
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum