Skip to content

feat: add support for base64url regex validator#1557

Open
hazrid93 wants to merge 1 commit into
open-circle:mainfrom
hazrid93:hazrid93/30_947
Open

feat: add support for base64url regex validator#1557
hazrid93 wants to merge 1 commit into
open-circle:mainfrom
hazrid93:hazrid93/30_947

Conversation

@hazrid93

@hazrid93 hazrid93 commented Jul 20, 2026

Copy link
Copy Markdown

Closes #947.

Add a base64Url(message?) action that validates the base64url alphabet with optional padding (both padded xx== and unpadded xx forms, since base64url commonly omits padding). The existing base64 action is unchanged.

Summary by CodeRabbit

  • New Features
    • Added Base64URL validation for checking whether values use the required encoding format.
    • Supports optional custom validation messages.
    • Exposed the validator through the public actions API.

Closes open-circle#947.

Add a `base64Url(message?)` action that validates the base64url alphabet with optional padding (both padded `xx==` and unpadded `xx` forms, since base64url commonly omits padding). The existing `base64` action is unchanged.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds a Base64URL validation action with a strict regular expression, public issue and action types, and overloads supporting optional custom messages. The action validates typed dataset values, records an issue for invalid values, and returns the dataset. The new action is re-exported through its module index and the main actions barrel.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a base64url regex validator.
Linked Issues check ✅ Passed The PR adds a new base64url validator and exports it, which matches the linked issue's request.
Out of Scope Changes check ✅ Passed The changes stay focused on the new base64url validator and its exports, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@library/src/actions/base64Url/base64Url.ts`:
- Line 31: Add JSDoc immediately before the first exported overload,
base64Url<TInput extends string>(), documenting the function’s purpose and usage
according to the project’s existing action documentation conventions; do not
duplicate documentation on subsequent overloads.
- Around line 8-9: Update BASE64URL_REGEX to enforce valid Base64URL padding:
require exactly two padding characters or none for a 2-character final block,
and allow at most one optional padding character for a 3-character block.
Preserve acceptance of unpadded valid strings while rejecting incorrectly padded
values such as “ab=”.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 092ddcc3-0a41-42e3-9157-df3a782d77e0

📥 Commits

Reviewing files that changed from the base of the PR and between 90bc2c7 and da0123f.

📒 Files selected for processing (3)
  • library/src/actions/base64Url/base64Url.ts
  • library/src/actions/base64Url/index.ts
  • library/src/actions/index.ts

Comment on lines +8 to +9
const BASE64URL_REGEX: RegExp =
/^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}={0,2}|[\da-z_-]{3}={0,1})?$/iu;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Fix regex to reject incorrectly padded strings.

The ={0,2} quantifier allows a single padding character (=) for a 2-character base64 block, which mathematically represents an invalid encoding (e.g., ab=). A 2-character block must have exactly two padding characters (==) or none. Use (?:==)? and =? to enforce correct padding lengths.

🐛 Proposed fix for the regex
-const BASE64URL_REGEX: RegExp =
-  /^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}={0,2}|[\da-z_-]{3}={0,1})?$/iu;
+const BASE64URL_REGEX: RegExp =
+  /^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}(?:==)?|[\da-z_-]{3}=?)?$/iu;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const BASE64URL_REGEX: RegExp =
/^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}={0,2}|[\da-z_-]{3}={0,1})?$/iu;
const BASE64URL_REGEX: RegExp =
/^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}(?:==)?|[\da-z_-]{3}=?)?$/iu;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@library/src/actions/base64Url/base64Url.ts` around lines 8 - 9, Update
BASE64URL_REGEX to enforce valid Base64URL padding: require exactly two padding
characters or none for a 2-character final block, and allow at most one optional
padding character for a 3-character block. Preserve acceptance of unpadded valid
strings while rejecting incorrectly padded values such as “ab=”.

readonly message: TMessage;
}

export function base64Url<TInput extends string>(): Base64UrlAction<

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add missing JSDoc to the exported function.

As per coding guidelines, JSDoc required on exported functions (first overload only for overload sets).

📝 Proposed fix to add JSDoc
+/**
+ * Creates a base64url validation action.
+ *
+ * `@returns` A base64url action.
+ */
 export function base64Url<TInput extends string>(): Base64UrlAction<
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function base64Url<TInput extends string>(): Base64UrlAction<
/**
* Creates a base64url validation action.
*
* `@returns` A base64url action.
*/
export function base64Url<TInput extends string>(): Base64UrlAction<
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@library/src/actions/base64Url/base64Url.ts` at line 31, Add JSDoc immediately
before the first exported overload, base64Url<TInput extends string>(),
documenting the function’s purpose and usage according to the project’s existing
action documentation conventions; do not duplicate documentation on subsequent
overloads.

Source: Coding guidelines

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="library/src/actions/base64Url/base64Url.ts">

<violation number="1" location="library/src/actions/base64Url/base64Url.ts:9">
P1: The regex accepts invalid padding `xx=` (2 data chars with exactly 1 `=`), which is neither properly padded (`xx==`) nor unpadded (`xx`). For example, `"aA="` would incorrectly validate. Change `={0,2}` to `(?:==)?` to only allow exactly 0 or 2 padding chars, matching the base64url specification.</violation>

<violation number="2" location="library/src/actions/base64Url/base64Url.ts:9">
P2: Malformed padding and non-ASCII characters pass validation: `Zg=` is accepted, and Unicode case-folded letters match under `/iu`. Require either no padding or exact RFC padding, and use an explicit ASCII case range.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

import { _addIssue } from '../../utils/index.ts';

const BASE64URL_REGEX: RegExp =
/^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}={0,2}|[\da-z_-]{3}={0,1})?$/iu;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The regex accepts invalid padding xx= (2 data chars with exactly 1 =), which is neither properly padded (xx==) nor unpadded (xx). For example, "aA=" would incorrectly validate. Change ={0,2} to (?:==)? to only allow exactly 0 or 2 padding chars, matching the base64url specification.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/base64Url/base64Url.ts, line 9:

<comment>The regex accepts invalid padding `xx=` (2 data chars with exactly 1 `=`), which is neither properly padded (`xx==`) nor unpadded (`xx`). For example, `"aA="` would incorrectly validate. Change `={0,2}` to `(?:==)?` to only allow exactly 0 or 2 padding chars, matching the base64url specification.</comment>

<file context>
@@ -0,0 +1,60 @@
+import { _addIssue } from '../../utils/index.ts';
+
+const BASE64URL_REGEX: RegExp =
+  /^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}={0,2}|[\da-z_-]{3}={0,1})?$/iu;
+
+export interface Base64UrlIssue<TInput extends string>
</file context>

import { _addIssue } from '../../utils/index.ts';

const BASE64URL_REGEX: RegExp =
/^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}={0,2}|[\da-z_-]{3}={0,1})?$/iu;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Malformed padding and non-ASCII characters pass validation: Zg= is accepted, and Unicode case-folded letters match under /iu. Require either no padding or exact RFC padding, and use an explicit ASCII case range.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/base64Url/base64Url.ts, line 9:

<comment>Malformed padding and non-ASCII characters pass validation: `Zg=` is accepted, and Unicode case-folded letters match under `/iu`. Require either no padding or exact RFC padding, and use an explicit ASCII case range.</comment>

<file context>
@@ -0,0 +1,60 @@
+import { _addIssue } from '../../utils/index.ts';
+
+const BASE64URL_REGEX: RegExp =
+  /^(?:[\da-z_-]{4})*(?:[\da-z_-]{2}={0,2}|[\da-z_-]{3}={0,1})?$/iu;
+
+export interface Base64UrlIssue<TInput extends string>
</file context>

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

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for base64url regex validator

1 participant