Skip to content

Trim whitespace from tokens before tokenising#9847

Open
mintsoft wants to merge 1 commit intoopnsense:masterfrom
mintsoft:trimtokens
Open

Trim whitespace from tokens before tokenising#9847
mintsoft wants to merge 1 commit intoopnsense:masterfrom
mintsoft:trimtokens

Conversation

@mintsoft
Copy link
Copy Markdown

@mintsoft mintsoft commented Feb 23, 2026

Previously if you pasted an IP or similar in whitespace on either side it will automatically put it into a token box and then error on save.

The only way to fix that is to paste into an editor, fix the data and then copy-paste back into opnsense. This should trim before tokenizing the data

Fixes: #9438

…de it will automatically put it into a token box and then error on save

The only way to fix that is to paste into an editor, fix the data and then copy-paste back into opnsense. This should trim before tokenizing the data
@fichtner
Copy link
Copy Markdown
Member

It's a good idea on the surface, but it doesn't fix much and leads to other problems. My favourite example is that the code used to trim a password for no good reasons. It's asking for trouble later than just making sure the pasted data is clean.

Cheers,
Franco

@mintsoft
Copy link
Copy Markdown
Author

Hmm, you make a good point regarding the password and I understand your concerns however my reading of the code is that this won't affect that anyway, it's only in the situation where the tokenizer is hooked into the list (which seems to be multi-select only).

WRT to significance, I honestly couldn't disagree more strongly. This is an absolutely infuriating experience for any experienced person using opnsense. It's a super common problem to have when you're setting up VPNs to copy and paste out of browsers which frequently will crowbar whitespace before and after values and there is no way to resolve it in-ui because the tokenizer kicks-in before you're able to fix it.

An alternative place to do this (which is more targeted, https://github.com/opnsense/core/pull/9847/changes#diff-31373581f35eaa592e76f126a2d240ffdd432a076ec95cb5d8ae1f047716edceR321) would be in the last step when it wraps the values in the li. At that point it is about to write the invalid data into the DOM, so it is inevitable that the next interaction that the user has with the box is to delete the value when the save validation fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Could you please add .trim() to the FW alias network/host tokenizer?

2 participants