Repository navigation
fix: refuse displacing a section definition paragraph by insert or move - #497
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
A section's first body paragraph owns its setup (`Control::SectionDef` plus the column definition). PR #450 guarded the addressed splice, but two entry points could still place another paragraph in front of it: the anchored `insert_para` (an `anchor` selector) and `move_para` to index 0 of a section body. Neither native writer can repair that afterwards - HWPX injects a second, default `secPr` on the new first paragraph while the original setup is still written later, and HWP5 leaves the section without secd/cold. `insert_paragraph` now delegates to a checked variant that returns the one refusal a `bool` could not express, keeping its public signature for existing callers. The CLI flag form and the typed `insert_para` anchor selector call the checked variant, so the cause and remedy reach the user instead of the generic anchor-miss message. `move_paragraph` refuses a destination index of 0 on a section body list before it removes the source; nested lists (cells, captions) carry no section setup and stay allowed. Both refusals share the addressed guard's wording through one constant. The existing `move_paragraph` unit tests moved a paragraph to index 0 to show that `instance_id` and anchored controls travel with the paragraph. Those two assertions are kept and the destination moved behind the owner, because displacing the owner is exactly what this change forbids; a new unit test pins the refusal itself. The `edit-ops` tracer fixture anchored `insert_para` on the section owner, so its markdown gains a trailing paragraph and the fixture anchors there, keeping before=true covered inside the new boundary. Refusal and control cases run over composed HWP5 and HWPX documents built by `hwp new --from` (so the owner carries text an anchor search can name).
entelecheia
force-pushed
the
fix/451-section-owner-paths
branch
from
November 10, 2026 16:40
b630c89 to
d2e66dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A section's first body paragraph owns its section setup (
Control::SectionDefand the columndefinition). PR #450 (#428 T2) guarded the addressed splice (
insert_paragraphs_at, used byinsert_blocksand addressedinsert_para), but two entry points could still place anotherparagraph in front of that owner:
insert_paragraph(doc, anchor, text, before = true), when the matched anchor paragraphis the section owner;
move_paragraphto index 0 of a section body — it already refused moving the owner itself, notmoving another paragraph in front of it.
Neither native writer repairs the result. HWPX (
crates/hwpx/src/write/section.rs) injects adefault
secPrinto the new first paragraph while the original setup is still written later, sothe section ends up with two setups and the first one has default page size, margins and
header/footer settings; HWP5 leaves the first paragraph without secd/cold and only sets
break_type.Change
insert_paragraph_checked(doc, anchor, text, before) -> Result<bool, String>is the one placethat decides this boundary:
Ok(true)inserted,Ok(false)no anchor matched (theboolform's behaviour),
Errthe refusal, always before any mutation.insert_paragraphkeeps itspublic signature and delegates, so every existing
boolcaller and test still compiles.insert_paragraphs_atand the new checked variant share oneSECTION_OWNER_INSERT_REFUSALconstant, so
insert_blocks, addressedinsert_paraand anchoredinsert_paragive the samecause and the same remedy (
position=after/before=false).move_paragraphrefusesto_index == 0on a section body list when that list's first paragraphcarries
Control::SectionDef, in its existing pre-mutation validation block. Nested lists (cells,captions) carry no section setup and stay allowed.
crates/hwp-cli/src/commands/edit.rs): the flag-form--insert-para-before/--insert-paraarms and the typed
insert_paraanchor selector call the checked variant, so the refusal reachesthe user instead of the generic anchor-miss message.
Korean development-comment lines in the touched
hwp-convert/src/lib.rswere translated toEnglish (meaning preserved, user-facing strings untouched).
Tests
Refusal and control cases run over
hwp new --frombases for bothhwpandhwpx, becausethe composed fixture used by
insert_blockskeeps its section setup on an empty first paragraphthat no anchor search can name:
anchored_insert_para_before_section_definition_refuses_in_both_formatsinsert_parawithanchoron the owner andbefore=truefails, the message carries 구역/앞 and thebefore=falseremedy, the source bytes are unchanged and no output file is publishedbefore=falseinserts at index 1 and the owner stays firstmove_para_before_section_definition_refuses_in_both_formatsmove_parafrom paragraph 2 tobeforeparagraph 0 fails with the boundary in the message, source and destination untouchedRed-first against this branch's pre-fix tree (
0358c84, both tests present, guard absent):With the guards in place the same two lines report
test result: ok. 2 passed.Two existing assertions had to move, not weaken:
structure::tests::move_paragraph_문단_이동_id_보존andmove_paragraph_앵커_컨트롤도_함께_이동moved a paragraph to index 0 to prove
instance_idand anchored controls travel with it. They nowmove behind the owner (index 1) and keep exactly those assertions;
move_paragraph_구역정의_앞으로는_거부pins the refusal itself, including that nothing moved.
edit-opstracer fixture anchoredinsert_paraon the section owner, soTRACER_MDgains atrailing paragraph and
fixtures/edit-ops/tracer.jsonanchors there;before=truecoverage iskept inside the new boundary and the test now also asserts the owner stays first.
Verification
Local:
cargo test -p hwp-convert(600 lib),cargo test -p hwp-cli(all targets, incl. 85edit_opsand 51insert_blocks),cargo fmt --all --check.Hancom open/export verification is a separate person-run evidence leg and was not performed here.
This change refuses paths rather than repairing writers, so it introduces no new format rule.
Closes #451.