FIX Prof id pasted with its separator spaces is truncated (SIREN, SIRET) - #39679
Open
daGrumpf-bxp wants to merge 1 commit into
Open
FIX Prof id pasted with its separator spaces is truncated (SIREN, SIRET)#39679daGrumpf-bxp wants to merge 1 commit into
daGrumpf-bxp wants to merge 1 commit into
Conversation
daGrumpf-bxp
force-pushed
the
fix/profid-paste-with-separator-spaces
branch
from
August 23, 2026 18:57
3337da1 to
7e2b820
Compare
A SIREN is presented everywhere as "849 943 618" and a SIRET as "849 943 618 00012", so that is what a user copies. The input built by get_input_id_prof() carries maxlength=9 (resp. 14), and that length counts the pasted spaces: the browser silently drops the end of the paste and the third party is recorded with "849 943 6". Nothing warns about it, and the value looks right at a glance. The spaces are now removed from the pasted text before it is inserted, so that maxlength applies to the id itself instead of to its presentation. Widening maxlength would not do: it counts characters, not separators, and three digits too many would go through just as well as three spaces. The paste handler lives in lib_head.js.php and only acts on the inputs marked by get_input_id_prof() with data-profidnospace, that is the ids whose recorded value never holds a space (isProfIdWithoutSpace(): the ones isValidProfIds() checks after having removed the spaces). A French idprof4 keeps the spaces of "RCS Poitiers B 849 943 618", and every maxlength stays exactly what it was. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012WXV1H3xDj9tnAKfSw5DSU
daGrumpf-bxp
force-pushed
the
fix/profid-paste-with-separator-spaces
branch
from
August 23, 2026 19:19
7e2b820 to
252b617
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.
FIX Prof id pasted with its separator spaces is truncated (SIREN, SIRET)
A SIREN is presented everywhere as
849 943 618, a SIRET as849 943 618 00012— on the Kbis, on the INSEE certificate, on the invoices of the third party. That is what the user copies, and what they paste into "Id prof 1" / "Id prof 2" of a third party.The input built by
FormCompany::get_input_id_prof()carriesmaxlength="9"(resp.14), and that length counts the pasted spaces. The browser silently drops the end of the paste, and the third party is recorded with849 943 6. Nothing warns about it, and at a glance the value looks right.Reproduce (France,
MAIN_DISABLEPROFIDRULESoff)849 943 618and paste it in "Id prof 1 (SIREN)"849 943 6— three digits shortllx_societe.siren=849 943 6, and the card shows a "wrong value" warningWorse than the warning: pasting an id that is a few characters too long, say
84994361812, truncates to849943618, which passes the Luhn check and displays with its link to the public directory. A slip silently becomes another company's identity.Fix
The separator spaces are removed from the pasted text before it is inserted, so
maxlengthapplies to the id itself rather than to its presentation.Widening
maxlengthwould not do: it counts characters, not separators, so three digits too many would go through just as well as three spaces — the length guard would be lost for the exact case above.isProfIdWithoutSpace()tells whether a space in a prof id can only be a separator. That is the case of the idsisValidProfIds()checks, since each of those checks strips the spaces first: FR 1 and 2, ES/PT/DZ/BE 1.get_input_id_prof()marks those inputs withdata-profidnospace. Nomaxlengthchanges, on any field.lib_head.js.phpgets a delegatedpastehandler oninput[data-profidnospace]: it cleans the pasted text and inserts it withexecCommand("insertText"), which keeps the undo history and — unlikesetRangeText— remains subject to the field'smaxlength. A paste with nothing to clean is left to the browser untouched.A French idprof4 keeps the spaces of
RCS Poitiers B 849 943 618, since it carries no marker.Tests
test/phpunit/ProfidLibTest.phpgetstestIsProfIdWithoutSpace().Checked by hand on a 24.0 instance, France, third party creation then edit, with real
Ctrl+Vpastes:849 943 618(idprof1)849943618849943618732 829 320 00074(idprof2)732829320000747328293200007484994361812(idprof1, 11 digits)849943618— truncated to 9, as before this PR73282932000074999(idprof2, 17 digits)73282932000074— truncated to 14, as before this PRRCS Poitiers B 732 829 320(idprof4)RCS Poitiers B 732 829 320732 829 320 00074 77(idprof1)732829320— the SIREN732829320732 829 320 00074 77(idprof2)73282932000074— the SIRET73282932000074The card then shows
849 943 618and732 829 320 00074, grouped again bydol_print_profids(), with no "wrong value" warning.The last two rows are worth a word: French ids nest by prefix — a SIRET is the 9 digits of the SIREN followed by the 5 of the NIC. Once the separators are out of the way, the
maxlengtheach field already had isolates exactly the right id, so pasting a whole SIRET into "Id prof 1" now yields the SIREN. The same paste used to give732 829 3there, and732 829 320 00in "Id prof 2" — two values fit for the bin.The bug is old and present on every maintained branch; I am targeting 24.0 because the fix adds a function to
profid.lib.php. Say the word and I retarget todevelop, or to an older branch if you would rather have it there.