Fix parseVersion regex, theme switcher init, changelog regex cache, and workflow label escaping - #70
Fix parseVersion regex, theme switcher init, changelog regex cache, and workflow label escaping#70mobileskyfi with Copilot wants to merge 3 commits into
Conversation
…workflow validator Agent-Logs-Url: https://github.com/tikoci/restraml/sessions/adb6bc76-a79e-4b2c-9cac-662eec232684 Co-authored-by: mobileskyfi <45924209+mobileskyfi@users.noreply.github.com>
…n m[4] does Agent-Logs-Url: https://github.com/tikoci/restraml/sessions/adb6bc76-a79e-4b2c-9cac-662eec232684 Co-authored-by: mobileskyfi <45924209+mobileskyfi@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes several correctness issues in docs and tooling by tightening version parsing, ensuring theme switcher UI initializes reliably, reusing compiled changelog header regexes, and correcting workflow label escaping.
Changes:
- Fix
parseVersion()pre-release parsing by requiring digits afterbeta/rcand simplifyingpreNumlogic. - Initialize the theme switcher icon immediately instead of waiting on a
DOMContentLoadedhandler that may never run. - Cache compiled changelog header regexes and fix a broken regex character class used for runner-label suppression.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| docs/restraml-shared.js | Fix version parsing, initialize theme icon correctly, and add cached regex for changelog header matching. |
| validate-workflows.mjs | Fix regex escaping so labels are safely embedded in a RegExp. |
| const _clHeaderRegexCache = new Map() | ||
| function _clGetHeaderRegex(version) { | ||
| let re = _clHeaderRegexCache.get(version) | ||
| if (!re) { | ||
| re = new RegExp(`What's new in ${_clEscapeRegex(version)} \\(([^)]+)\\)`, 'i') | ||
| _clHeaderRegexCache.set(version, re) | ||
| } |
There was a problem hiding this comment.
This cache can grow without bound because showChangelog(version) is a public API surface and can be called with arbitrarily many distinct version values (including user-driven input). Consider bounding the cache (LRU / max size), normalizing inputs, or avoiding caching unless the set of versions is known to be small and finite.
| const _clHeaderRegexCache = new Map() | |
| function _clGetHeaderRegex(version) { | |
| let re = _clHeaderRegexCache.get(version) | |
| if (!re) { | |
| re = new RegExp(`What's new in ${_clEscapeRegex(version)} \\(([^)]+)\\)`, 'i') | |
| _clHeaderRegexCache.set(version, re) | |
| } | |
| const _CL_HEADER_REGEX_CACHE_MAX = 128 | |
| const _clHeaderRegexCache = new Map() | |
| function _clGetHeaderRegex(version) { | |
| const cacheKey = String(version).trim() | |
| let re = _clHeaderRegexCache.get(cacheKey) | |
| if (re) { | |
| _clHeaderRegexCache.delete(cacheKey) | |
| _clHeaderRegexCache.set(cacheKey, re) | |
| return re | |
| } | |
| re = new RegExp(`What's new in ${_clEscapeRegex(cacheKey)} \\(([^)]+)\\)`, 'i') | |
| _clHeaderRegexCache.set(cacheKey, re) | |
| if (_clHeaderRegexCache.size > _CL_HEADER_REGEX_CACHE_MAX) { | |
| const oldestKey = _clHeaderRegexCache.keys().next().value | |
| _clHeaderRegexCache.delete(oldestKey) | |
| } |
Four independent correctness bugs in
docs/restraml-shared.jsandvalidate-workflows.mjs.parseVersion— regex and preNum logic (restraml-shared.js:53)The qualifier and digit groups were independent optionals, so
7.22beta(no trailing number) silently matched withpreNum: 0instead of returningnull, causing incorrect version sorting.The new regex also makes the
preNumternary simpler —m[5]is now guaranteed whenm[4]exists:initThemeSwitcher— icon never initialized (restraml-shared.js:211)The initial icon was set inside a
DOMContentLoadedlistener registered insideinitThemeSwitcher(), which is called after DOM load. The listener never fires, leaving the theme icon blank.Replaced with a direct assignment at call time.
Changelog header regex — per-render
new RegExp(restraml-shared.js)showChangelogconstructednew RegExp(...)on every call. Added_clHeaderRegexCache(aMap) so the compiled regex is reused across repeated lookups for the same version.Workflow label escaping — broken character class (
validate-workflows.mjs:40)/[.*+?^${}()|[\\\]]/ghas a misplaced backslash that breaks the character class boundary. Fixed by moving\\to the end:/[.*+?^${}()|[\]\\]/g.Original prompt