[Bug 43776] New: TransformHtmlToMarc should repair and report invalid characters rather than silently stripping them
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Bug ID: 43776 Summary: TransformHtmlToMarc should repair and report invalid characters rather than silently stripping them Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Cataloging Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org CC: m.de.rooy@rijksmuseum.nl Target Milestone: --- Bug 35104 removed the inline StripNonXmlChars calls from C4::Biblio::TransformHtmlToMarc on the assumption that Koha::Biblio::Metadata->store() now strips centrally. TransformHtmlToMarc never calls store(): it builds a MARC::Record from submitted form values, and callers such as cataloguing/addbiblio.pl (FindDuplicate, duplicate redisplay), cataloguing/merge.pl and svc/cataloguing/automatic_linker.pl use that record without saving it. Control characters pasted into the form therefore reached MARC::Record/XML serialisation again, the same failure bug 34549 fixed. The RM follow-up on bug 35104 restored the two StripNonXmlChars calls as a stop-gap. That only covers non-XML characters in the first subfield of a new field and in control fields; it does not cover the other faults Koha::Biblio::Metadata->repair_marcxml handles (e.g. empty datafields), and it silently discards data without telling the cataloguer. Proposal: - Have TransformHtmlToMarc validate its result with the same logic as repair_marcxml instead of stripping inline. - Recoverable faults are repaired and reported to the caller (so the cataloguer can be shown what was changed). - Unrecoverable input throws Koha::Exceptions::Metadata::Invalid, as store() does. - Callers catch the exception and tell the user: addbiblio.pl and merge.pl show the message in the form/merge page, the automatic_linker svc returns a clear error. authorities/ callers need a decision, since authorities do not go through Koha::Biblio::Metadata. Test plan: 1. Apply the patches on top of bug 35104. 2. In the cataloguing editor, paste a control character (e.g. U+001F) into a subfield of a new record, then use Save/Duplicate. Confirm the record is saved or redisplayed with a warning describing what was stripped, and no 500 error. 3. Submit a form producing an empty datafield. Confirm it is repaired and reported. 4. Run prove t/db_dependent/Biblio/TransformHtmlToMarc.t Sponsored-by: OpenFifth -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk Depends on| |35104 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35104 [Bug 35104] We should warn when attempting to save MARC records that contain characters invalid in XML -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on|35104 |43777 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35104 [Bug 35104] We should warn when attempting to save MARC records that contain characters invalid in XML https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43777 [Bug 43777] Koha::Biblio::Metadata->record should repair recoverable MARCXML faults on read -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on|43777 |43025 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43025 [Bug 43025] Show metadata repair warnings in the cataloguing edit form https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43777 [Bug 43777] Koha::Biblio::Metadata->record should repair recoverable MARCXML faults on read -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 211489 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211489&action=edit Bug 43776: Repair and report invalid characters in TransformHtmlToMarc TransformHtmlToMarc stripped non-XML characters from the submitted values inline and silently, so the cataloguer was never told their data had been changed. Bug 35104 removed that stripping on the assumption that store() handled it, and the RM follow-up restored it without any report. TransformHtmlToMarc now checks its result the same way Koha::Biblio::Metadata does when saving: it serialises the record and, if the XML does not read back, repairs the recoverable faults with repair_marcxml. The repairs are returned through an optional third argument. Unrecoverable input throws Koha::Exceptions::Metadata::Invalid. Repairs are passed to AddBiblio and ModBiblio with the new repairs option. They are recorded as metadata error rows and reported as warnings, as Koha::Biblio::Metadata->store already does for repairs made on save. The cataloguing editor therefore shows the "Record saved with modifications" banner after a save, and the form shows the repaired values when a duplicate check stops the save. Merge reports them as merge warnings. Unrecoverable input is caught by addbiblio.pl, merge.pl and the automatic linker service and reported as an error instead of a 500. Authority callers keep the inline stripping, as authority records are not stored through Koha::Biblio::Metadata; that is left for a follow-up decision. Koha::Biblio::Metadata gains add_repairs (the recording loop from store) and repair_messages (the same text as a list, for records not yet saved). To test: 1. Apply this patch on top of bug 43025 (which depends on bug 35104). 2. In the cataloguing editor, add a new record and paste a control character (e.g. U+001F) into a subfield value, then save. => The record saves and the "Record saved with modifications" banner names the character that was removed. 3. Edit a record, paste the same character, and save a record that trips the duplicate check so the form is redisplayed without saving. => The "Data repaired in the form" notice names the character; nothing is saved. 4. Merge two records where one has the same character in a field. => The merge completes and its warnings name the repair. 5. Run prove t/db_dependent/Biblio/TransformHtmlToMarc.t => All tests pass. 6. Run prove t/db_dependent/Biblio.t t/db_dependent/Koha/Biblio/Metadata.t => All tests pass. Sponsored-by: OpenFifth Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44072 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44072 [Bug 44072] Report repairs made to authority records in TransformHtmlToMarc instead of stripping silently -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44073 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44073 [Bug 44073] Automatic linker ignores the INVALID_METADATA status returned for unrepairable records -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off Sponsorship status|--- |Sponsored Comma delimited| |OpenFifth list of Sponsors| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211489|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 --- Comment #2 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 211547 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211547&action=edit Bug 43776: Repair and report invalid characters in TransformHtmlToMarc TransformHtmlToMarc stripped non-XML characters from the submitted values inline and silently, so the cataloguer was never told their data had been changed. Bug 35104 removed that stripping on the assumption that store() handled it, and the RM follow-up restored it without any report. TransformHtmlToMarc now checks its result the same way Koha::Biblio::Metadata does when saving: it serialises the record and, if the XML does not read back, repairs the recoverable faults with repair_marcxml. The repairs are returned through an optional third argument. Unrecoverable input throws Koha::Exceptions::Metadata::Invalid. Repairs are passed to AddBiblio and ModBiblio with the new repairs option. They are recorded as metadata error rows and reported as warnings, as Koha::Biblio::Metadata->store already does for repairs made on save. The cataloguing editor therefore shows the "Record saved with modifications" banner after a save, and the form shows the repaired values when a duplicate check stops the save. Merge reports them as merge warnings. Unrecoverable input is caught by addbiblio.pl, merge.pl and the automatic linker service and reported as an error instead of a 500. Authority callers keep the inline stripping, as authority records are not stored through Koha::Biblio::Metadata; that is left for a follow-up decision. Koha::Biblio::Metadata gains add_repairs (the recording loop from store) and repair_messages (the same text as a list, for records not yet saved). To test: 1. Apply this patch on top of bug 43025 (which depends on bug 35104). 2. In the cataloguing editor, add a new record and paste a control character (e.g. U+001F) into a subfield value, then save. => The record saves and the "Record saved with modifications" banner names the character that was removed. 3. Edit a record, paste the same character, and save a record that trips the duplicate check so the form is redisplayed without saving. => The "Data repaired in the form" notice names the character; nothing is saved. 4. Merge two records where one has the same character in a field. => The merge completes and its warnings name the repair. 5. Run prove t/db_dependent/Biblio/TransformHtmlToMarc.t => All tests pass. 6. Run prove t/db_dependent/Biblio.t t/db_dependent/Koha/Biblio/Metadata.t => All tests pass. Sponsored-by: OpenFifth Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adolfo.rodriguez@xercode.es --- Comment #3 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Tested in the basic editor, adding a control character (U+001F) to 245$a from the browser console before saving: - Before the patch, the record saved with the character silently stripped: no message and no metadata error row. The duplicate check and the merge also stripped it without any notice. - After the patch: - Saving a new record shows the "Record saved with modifications" banner naming the removed character, and the repair is recorded in biblio_metadata_errors. - When the duplicate check stops the save, the "Data repaired in the form" notice names the character, and nothing is saved. - A merge whose result had the character completes, and the merge warnings name the repair. The QA script is happy, and t/db_dependent/Biblio/TransformHtmlToMarc.t, t/db_dependent/Biblio.t and t/db_dependent/Koha/Biblio/Metadata.t pass. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43776 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |lisette@bywatersolutions.co |y.org |m -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org