fix(search): render the custom search result prefix - #6337
e107help[bot] wants to merge 1 commit into
Conversation
fa21769 to
c2e4a59
Compare
|
Back in step with master: this branch is rebased onto Only
On the rebased tree the unit suite is green (2705 tests, 25754 assertions, 6 skipped), the downgrade tooling converges with no rewrites, and the case for this fix is still red with the two source files reverted and green with them restored. |
c2e4a59 to
d337b39
Compare
|
Both of the remaining search branches went onto one master tip tonight, in a single pass, so this one and #6325 can be merged back to back without either re-conflicting behind the other. This branch is rebased onto What conflicted
Master's That one line is One fix absorbed while hereThe same meeting of the two mechanisms left a gap the rebase created. This branch makes Why the tests moved within the fileEach of these branches conflicted with master, and they also conflicted with each other: this branch and #6325 each appended their block to the tail of the same class, so merging either one would have left the other dirty. So the two blocks now have different anchors. This branch's four prefix cases and their helpers sit at the boundary between the highlighting group and The result is measured on all three pairings, and every one merges clean:
So either order works, and the second one in does not need another rebase. On the rebased headThe whole unit suite is green on PHP 8.2 and MariaDB 10.11: 2722 tests, 25816 assertions, 6 environmental skips. The downgrade tooling converges on the tree with no rewrites. The case this fix exists for is still red with Two things left openNeither is a regression this branch introduces, and both are named here rather than fixed because the fix would touch a file #6325 also edits, which would put the collision straight back:
RecommendationMerge, together with #6325 and in either order. The behaviour is pinned by four cases, modes |
|
The It is the same source change, hunk for hunk, and it carries these four cases with it. What differs is only what that branch forces: the news item is seeded through the database API v2.3.x has rather than the query builder it has not, the insert sets One of the two things left open above is fixed on the twin instead of here. Its cleanup child reports whether it took the seeded news item back out, and the case fails when it did not, which matters because the unit suite loads its dump once per run and opens no per-test transaction: a row that survives its case is live on the site for every test after it. Doing the same on this branch would touch The order is what it was: this one merges first and the twin follows it, and both of those are Deltik's calls. |
The search page collapsed the pre_title mode into the prefix text before the renderer saw either, so the renderer compared a piece of prose against 0, 1 and 2, matched none of them on PHP 8, and left $pre_title_output undefined. The custom prefix has therefore never appeared in v2: on PHP 7 the same string was loosely equal to 0 and the prefix was dropped in silence instead. The mode and the text now travel separately, and the renderer's branch ends in an else so the prefix is always defined. Mode 2 emits the site's text followed by a single space, matching the separator the addons carry in their own prefixes, so a prefix of "News" reads "News My article" rather than "NewsMy article". Modes 0 and 1 render byte for byte as before. A legacy sfile handler that reads the global $pre_title now sees the mode on a mode-2 handler, where it used to see the text; core ships no such handler. Fixes #6327
d337b39 to
a1bcb20
Compare
|
This one has moved onto the family's chain rather than sitting beside it. The base is now The change itself is untouched: the diff against the new base has the same patch id it had before the rebase, and the tests in it are the same four cases. Why the move, when this branch and #6325 were measured as merge-in-either-order only yesterday: two more branches have since appended to the tail of the same test class, and with three lines of work writing at one anchor, "either order" stops being something that can be promised for one pair without re-proving it for the whole set. One chain replaces all of that. The order for the whole block, and what a stacked base means at merge time, is in #6325; this one is fourth. Its |

Why
A search handler's result prefix has three settings in admin: the handler's own prefix, none, or a text of your own. The third one has never rendered anything in v2.
The two halves disagree about who resolves the setting. The front end collapses the mode into the text before the renderer sees either, at
search.php#L806:The renderer then tests that value against the numbers again, at
e107_handlers/search_class.php#L382-L393. On PHP 8 a piece of prose equals none of0,1or2, so no branch runs,$pre_title_outputis never assigned, and the next line reads an undefined variable: the prefix is dropped and a warning is raised per result. On PHP 7 the same string was loosely equal to0, so the prefix was dropped in silence instead.The mode-2 arm was
$pre_title_output = $pre_title;, which would have printed the literal2even if the mode had reached it intact. Both sides were wrong, which is why no PHP version ever rendered this.Fixes #6327
What Changed
search.phpforwards the two prefs as they are stored, the mode in$pre_titleand the text in$pre_title_alt, instead of collapsing one into the other.e107_handlers/search_class.phpreads both, and its branch now ends in anelse, so$pre_title_outputis defined whatever the pref holds:1, the handler's own prefix, unchanged2, the site's text, trimmed and followed by a single spaceThe space is the same convention the addons already follow in their own prefixes (
category_name." | ",LAN_SEARCH_71.": "). Without it a prefix ofNewswould renderNewsMy article, which is the fault #6298 was about, so shipping the feature without a separator would have been shipping it broken in a new way.Whether this setting deserves repairing at all is a fair question, since nobody can have been using it: the radio and its text box at
e107_admin/search.php#L356-L359could go instead, along with thepre_title_altpref. There is no recorded decision either way, and that choice is Deltik's, not this branch's. Repairing it leaves the option open; deleting the control would not.How It Was Tested
e107_tests/tests/unit/e_searchTest.phpgains four cases, in the file that already coverse_searchrather than in a second one. Each seeds one categorised news item, renders the search page for it in a subprocess, and asserts the exact contents of the result's<h4>link:2with a text set, the case this fixes, which also asserts that no undefined$pre_title_outputis reported anywhere on the page2with the text empty, which must not leave a stray space1, the handler's own prefix and its separator0, the title aloneThe first case is red on the unfixed sources and green with them restored, confirmed by reverting both files against the committed test rather than by reading. The whole unit suite is green: 2705 tests, 25754 assertions, 6 skipped. The tree parses, and the downgrade tooling converges on it with no rewrites.
The news item is seeded inside the subprocess, because the suite's own transaction is invisible to another connection and the sample dump seeds no news at all, and it is taken out again from the test's
_after()through a second booted CLI child, because a subprocess killed on its timeout runs no shutdown function. Word boundaries are switched off for the query so that the one regular expression path runs the same on MySQL 5.7 and 8.Backwards Compatibility
Modes
0and1render byte for byte as before, which the two guard cases above pin.Sites on mode
2start seeing a prefix that has never appeared, and stop collecting one undefined-variable warning per result. That is the point of the change, but it is a visible difference on upgrade for anyone who set that radio years ago and forgot.No tag, attribute or class in the rendered HTML changes, so a legacy skin is unaffected.
A third-party legacy
sfilehandler that reads the global$pre_titlesees the mode where a mode-2 handler used to hand it the text. Core ships no handler that reads it:$pre_titleis declaredglobalin exactly two places, and both are in this diff.$pre_title_altis new in that scope and shadows nothing.AI Model
Claude Opus 5 (claude-opus-5), as e107help.
Checklist
release/v2.3.xcarries the identical defect, and a twin there is Deltik's call rather than this branch's