gesinn-it-pub / mediawiki-extensions-PageForms

Fork of MediaWiki extension PageForms that aims to simplify contribution through hosting on GitHub instead of Gerrit, improved quality through better test coverage (to be done) and continuous integration.
Other
1 stars 4 forks source link

Unexpected encoding / conversion of query string #24

Open gesinn-it-gea opened 1 year ago

gesinn-it-gea commented 1 year ago

The Page Forms extension page on mediawiki.org gives the following advice:

Note that if any part of your query string — such as a page name or anything else — contains characters such as apostrophes ('), ampersands (&), or plus signs (+), you will need to URL-encode that value. For that, you can use the urlencode function from the ParserFunctions extension. The example above, for instance, would need to change to: Quote[Author]={{urlencode:{{PAGENAME}}}}.}}

Following the above advice using query string=Template[Field]={{urlencode:Test String}} leads to Test+String being displayed in the form field.

Summary: MW 1.35.8 PF 5.5.1

1) {{urlencode:Test String}} → Test+String 2) {{urlencode:Test_String}} → Test_String 3) {{urlencode:Test String&ampersand}} → Test+String&ampersand 4) Test String → Test String 5) Test_String → Test_String 6) Test String&ampersand → Test String

This leaves the user with no working combination for all cases.

krabina commented 1 year ago

There is also {{PAGENAMEE}} btw.

krabina commented 1 year ago

What about {{urlencode:Test String|WIKI}}?

gesinn-it-gea commented 1 year ago

The following commit introduced this breaking change. Before, it was working with default {{urlencode}}.

https://github.com/wikimedia/mediawiki-extensions-PageForms/commit/d29c9f37d23d1aea8b658148ce86c6df6b6bef4d#diff-31f9c3daecfcc90f5f898ed2e119979d92c59785d26dbac658845c2199067bbc

$queryString = str_replace( '+', '%2B', $queryString ); // prevent decoding + to space character

This change is related to #autoedit Modifying a list of values

gesinn-it-gea commented 1 year ago
7) {{urlencode:Test String|PATH}} → Test String
8) {{urlencode:Test_String|PATH}} → Test_String
9) {{urlencode:Test String&ampersand|PATH}} → Test String&ampersand
10) {{urlencode:Test String+plus|PATH}} → Test String+plus

Using option PATH seems to work. This option is not MW default and requires users to modify existing query strings.

Conclusion: this was a breaking change not marked as such.

gesinn-it-gea commented 1 year ago

A comparison between the different encodings can be found here: https://www.mediawiki.org/wiki/Manual:PAGENAMEE_encoding#Encodings_compared