Skip to content

Reject commas in route ids in the Studio UI validator - #174

Open
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:ui-route-id-validator
Open

vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:ui-route-id-validator

Conversation

@vharseko

Copy link
Copy Markdown
Member

Closes code scanning alerts #68 (js/regex/duplicate-in-character-class) and #67 (js/trivial-conditional), both warnings in openig-ui.

#68 — a real validation bug

The urlCompatible validator (used for the route id field in Studio) tested against /^[\d,a-z,-]+$/. Inside a character class the commas are literal characters, not separators, so an id like a,b passed validation — contrary to the i18n message "Use only lowercase letters, numbers and dash" and to generateRouteId(), which strips such characters. The class is now [\da-z-].

A "bad,id" → invalid case is added to OpenIGValidatorsTests.js.

#67 — cosmetic

createTreeNavigation.js: else if (data && !_.isArray(data))else if (!_.isArray(data)); data is already known to be truthy in that branch.

Verification

grunt build (eslint + babel + requirejs) passes.

Note on the QUnit suite: grunt qunit (grunt-contrib-qunit 1.3 / PhantomJS) times out locally and the qunit task is commented out of the build task, so the JS tests are not executed by the Maven build. To still get a red/green signal, the validator module was loaded in Node through a minimal AMD shim and exercised with every value from the QUnit test: before the fix 'bad,id' -> valid, after it invalid, the other seven cases unchanged. Reviving the QUnit runner (headless Chrome instead of PhantomJS) is a separate task.

The urlCompatible validator used the character class [\d,a-z,-], where
the commas are literal characters rather than separators, so a route id
such as "a,b" passed validation despite the "only lowercase letters,
numbers and dash" rule (js/regex/duplicate-in-character-class). Also
drop a redundant truthiness check in createTreeNavigation
(js/trivial-conditional).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug javascript Pull requests that update Javascript code tests Adds or updates tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant