Fix: MB-18 visual label editor silently destroys templates it can't fully r… - #508
Conversation
|
Warning Review limit reachedNext included review available in 42 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
SirRolin
left a comment
There was a problem hiding this comment.
Performed test:
Opened raw html editor.
Added a line.
Saved.
It correctly blocked me from accessing visual editor.
Deleted everything in the template.
Saved. -> it regenerated the default template.
It incorrectly blocks me from accessing the visual editor.
…abel SirRolin's PR review on DANOSOFT#508: deleting a 'Standard' label's raw HTML and saving left it stuck in raw-HTML mode. sys_div_func.php's labels() fills the empty-'Standard' textarea with a hardcoded placeholder (using the old $beskrivelse/$pris names) before running the MB-18 visually-editable guard, so the guard judged that placeholder instead of the actual (empty, and therefore visually-editable) stored text. Capture the stored text before the placeholder substitution and guard on that instead.
…dcoded_secrets.md) Same issue CodeRabbit flagged on PR DANOSOFT#507's SaveLabelTextCharacterization- Test: read connection details from the gitignored includes/connect.php instead of a checked-in literal, and skip the suite when the tenant db isn't reachable rather than erroring.
|
@SirRolin Fixed in 8065a5f — thanks for the repro steps, they pinpointed it exactly. Root cause: in Fix captures the stored text before the placeholder substitution and guards on that instead, so an emptied Also swapped the hardcoded Postgres credentials in Could you re-test the same repro when you get a chance? |
…elper if_isset($postFields['labelType'], 'sheet') evaluated the array access before the helper ran, warning on every case that didn't override labelType. Same calling-convention bug as SD-659/SD-660 - switched to the array+key form. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@SirRolin following up — could you re-test when you get a chance? This is the top of my queue for Monday's deadline (MB-17/MB-18 both hang on it). To directly re-verify your repro: raw HTML editor → delete everything → save. It now correctly returns to the visual editor instead of staying locked in raw mode. Added a regression test pinning exactly that ( Also cleaned up a stray No other changes since your review — just the targeted fix for what you found. |
Summary
Changing any label setting via the visual editor could overwrite/destroy a customer's
entire existing label configuration, instead of applying only the specific change made.
Root Cause
The visual label editor doesn't patch individual settings — every "Save" click rebuilds the
label's entire HTML from scratch (
generateLabelTemplate()) using a narrow, fixed set offields (columns, rows, margins, a handful of checkboxes, up to 5 custom text lines). Its
counterpart,
parseLabelTemplate(), can only recognize that exact same narrow shape whenreading a template back in. Anything outside it — custom CSS like
transform: rotate(),non-default dimensions, extra markup — is invisible to the parser, and is silently thrown
away the moment the visual editor regenerates and saves.
This wasn't a rare edge case: every label template Saldi ships (Brother 22606, Dymo 11354,
both "mit salg" variants) uses CSS the parser doesn't understand. Opening any of those in
the visual editor and saving any single setting — even something as trivial as text length —
would silently wipe out the real layout and replace it with generic filler.
What are the changes about?
labelTemplateEditableVisually($labelText)— runs the template throughparseLabelTemplate()→generateLabelTemplate()and checks whether that reproduces theoriginal exactly. If it doesn't, the template has content the visual editor can't safely
represent.
labels()) now forces raw-HTML mode, with an explanation, for any labelthat fails this check, instead of offering the destructive visual editor; "Switch to
Visual Editor" is hidden for unsafe labels.
$saveLabelPOST handler (systemdata/diverse.php) enforces the same checkserver-side — a save is refused, not silently destructive, whenever the label's current
template isn't visual-editor-safe. This is the authoritative guard; the UI change alone
couldn't be trusted to block every path.
Files Changed
labelTemplateEditableVisually()function;labels()now forces raw-HTML mode and hides "Switch to Visual Editor" for unsafe labels
$saveLabelPOST handler now checks the guard beforeregenerating/saving
(new) — 8 tests
How to Test
variants) in the label editor — verify each is forced into raw-HTML mode with an
explanation, and "Switch to Visual Editor" is not offered.
(bypassing the UI, e.g. via the POST handler) — verify the save is refused server-side and
the template is preserved byte-for-byte.
verify it still saves normally, confirming the guard doesn't over-block legitimate use.
LabelTemplateEditableVisuallyCharacterizationTest.test.phpand confirm all 8 casespass.
seed a real imported Brother template, simulate a "change one field" save) and confirm it
destroys the label (
rotategone, real 50mm width replaced by generic 38.1mm) — provingthe test suite actually pins this bug.
template is preserved exactly.
Acceptance Criteria
Verification
save — confirmed it genuinely destroyed the label (
rotategone, real 50mm width replacedby generic 38.1mm).
over-block).
Have you checked the following?
https://docs.google.com/document/d/1GOmomtvKf21OV2VWNOIPweDi4gJHpMCK5qXzrPrypUc/edit?usp=sharing