Page MenuHomePhabricator

Setting default value of form field to a URL results in HTML markup in field value
Closed, ResolvedPublic

Description

Author: alj62888

Description:
Hi,

When doing the following:

{{{field |url |text |default=http://sdf.com?xxx=yyy&zzz=aaa |maxlength=3000 |mandatory}}}

and when loading the form, the form field value gets set to:

<a rel="nofollow" class="external free" href="http://sdf.com?xxx=yyy&amp;zzz=aaa">http://sdf.com?xxx=yyy&amp;zzz=aaa</a>

instead of the proper unformatted value:

http://sdf.com?xxx=yyy&zzz=aaa

I tried wrapping the default value with <nowiki> but that doesn't work.

PLEASE NOTE: The description of how to reproduce above is just the most isolated way. Realistically, I'm actually setting the default dynamically with {{#urlget:...}} like so:

But, I removed the urlget, and urldecode, just to isolate the problem and hard-coding the default to a URL produces the same problem exactly.

Thanks,
Al


Version: REL1_20-branch
Severity: major
OS: Linux
Platform: PC

Details

Reference
bz47059

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 1:25 AM
bzimport set Reference to bz47059.

alj62888 wrote:

I'm not a php programmer, but I've done a little tracing and in SF_FormPrinter.php line 817 this is called:

$default_value = $wgParser->recursiveTagParse( $sub_components[1] );

and then the actual converting of the link to the marked-up version happens in Parser.php line 1166:

$text = $this->doMagicLinks( $text );

Hope this helps.

Q: Just a guess, but should the default value be parsed as markup like it is?

Yes, sometimes it makes sense to parse the default value - like when it contains an #ask query. It's really only when it holds a URL that problems seem to occur.

alj62888 wrote:

I'm musing on a private fix for this with a new param for the parser to skip the doMagicLinks() call. Is the presence of '#ask' the only thing to test for?

Well, if it's a private fix, it depends entirely on what's in your wiki.

alj62888 wrote:

I mean are there any other reasons, other than #ask, that a default value may need to be parsed?

Sure - #ifexists, #time, #expr, #show....

I recommend switching to recursivePreprocess from recursiveTagParse which handles all {{-constructs while leaving links, headers, bold etc. alone.

Yaron_Koren claimed this task.
Yaron_Koren subscribed.

@Nikerabbit - thanks for this great suggestion! And sorry for the long delay. I finally checked in the change you suggested, here:

https://gerrit.wikimedia.org/r/#/c/254141/

Marking this as resolved.