Static pages break with URL parameters

Found a bug? Tell us!!
Post Reply
hbarel
Regular
Posts: 8
Joined: Sun Apr 25, 2021 7:22 pm

Static pages break with URL parameters

Post by hbarel »

Hello,

Not sure if anyone noticed this, but when you call a static page with a URL parameter (such as those used for campaign tracking), the engine treats it as a page that is not found. For example: www.blog.com/pages/my-info.html?pk_medium=mail will throw you to the main-page. It will not dump the parameter, but will not load the right page either.

Ordinary posts pages work properly.
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Static pages break with URL parameters

Post by onli »

I can confirm the issue. https://www.onli-blogging.de/index.php? ... ntakt.html works, https://www.onli-blogging.de/index.php? ... &test=html leads to the frontpage.

The staticpage page plugin is a unwieldly, but work invested into it to fix bugs like this would be very welcome. Until then I would suggest to simply not add additional parameters ;)
hbarel
Regular
Posts: 8
Joined: Sun Apr 25, 2021 7:22 pm

Re: Static pages break with URL parameters

Post by hbarel »

I would be happy to have a look myself, but can anyone hint on where I need to look? Where is the part that parses /pages/....html names and passes them to render and display?
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Static pages break with URL parameters

Post by onli »

Sure! All of this is likely to happen in the staticpage plugin (but you should confirm that with debug output). The code lives at https://github.com/s9y/additional_plugi ... staticpage, with serendipity_event_staticpage.php containing most of the PHP code. This file will be in your installation under plugins/serendipity_event_staticpage/.

I assume https://github.com/s9y/additional_plugi ... .php#L3042 is a good starting point. The genpage hook is triggered when a page gets created, and is the likely entry point for the plugin to decide "No thanks, I will render this page". The line I link contains a call to serendipity_getUriArguments - that's a core function, and if the bug is there we would have to fix in in the core.

Fixing the bug should be about pinpointing which URL parts the plugin sees and whether the check is correct when it later compares the url part with the stored static pages it knows about (in selected() maybe?). At least that would be my guess. `echo` and especially `print_r()` should clear this up.
hbarel
Regular
Posts: 8
Joined: Sun Apr 25, 2021 7:22 pm

Re: Static pages break with URL parameters

Post by hbarel »

Thanks for the rather accurate pointers!
Indeed, there were two places where the URI parameters made it into the lookup, making the static page not found.
This can be resolved by stripping those parameters from $nice_url on two occasions, as I did in the enclosed patch.

Code: Select all

---
diff --git a/plugins/serendipity_event_staticpage/serendipity_event_staticpage.php b/plugins/serendipity_event_staticpage/serendipity_event_staticpage.php
index 8774572..c0ebd55 100644
--- a/plugins/serendipity_event_staticpage/serendipity_event_staticpage.php
+++ b/plugins/serendipity_event_staticpage/serendipity_event_staticpage.php
@@ -3057,7 +3057,7 @@ foreach($select AS $select_value => $select_desc) {
                     // This behavior might change in future releases.
                     $this->error_404 = ($_SERVER['REDIRECT_STATUS'] == '404');
 
-                    $pages = $this->fetchStaticPages(true, $nice_url);
+                    $pages = $this->fetchStaticPages(true, strtok($nice_url, "?"));
                     if (is_array($pages)) {
                     foreach ($pages as $page) {
                         if ($page['permalink'] == $nice_url) {
@@ -3082,7 +3082,7 @@ foreach($select AS $select_value => $select_desc) {
 
                     // Set static page according to requested URL
                     if (empty($serendipity['GET']['subpage'])) {
-                        $serendipity['GET']['subpage'] = $nice_url;
+                        $serendipity['GET']['subpage'] = strtok($nice_url, "?");
                     }
 
                     if ($this->selected()) {
On my deployment this seems to work.
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Static pages break with URL parameters

Post by onli »

It would be awesome if you could send this as a PR to the github repo, at https://github.com/s9y/additional_plugins/. Ideally also raise the version number from 1.19.2 to 1.19.3 and write a sentence about the fix into the Changelog. We'll give others a chance to test it like that and if no one protests I would merge it soon.
Post Reply