Skip to content

fix: regex for email#166

Merged
Oudwins merged 3 commits intomasterfrom
fix/email-regex
Jun 14, 2025
Merged

fix: regex for email#166
Oudwins merged 3 commits intomasterfrom
fix/email-regex

Conversation

@Oudwins
Copy link
Owner

@Oudwins Oudwins commented Jun 14, 2025

Closes #160

Summary by CodeRabbit

  • New Features
    • Added email and UUIDv4 validation functions for input checking.
  • Tests
    • Introduced comprehensive tests to verify email and UUIDv4 validation accuracy.
  • Refactor
    • Updated validation logic to use centralized helper functions for email and UUIDv4 checks.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 14, 2025

Caution

Review failed

The pull request is closed.

"""

Walkthrough

A new regex-based validation module is introduced for email and UUIDv4 formats, centralizing and updating the validation logic. The main string schema now delegates email and UUIDv4 checks to these new helpers. Comprehensive unit tests are added to verify correct validation behavior for both formats.

Changes

File(s) Change Summary
internals/is/regex.go Added new regex-based validators: Email and UUIDv4 functions with precompiled regexes.
internals/is/regex_test.go Introduced unit tests for Email and UUIDv4 validation functions covering valid/invalid cases.
string.go Removed inline regexes and updated validation to use is.Email and is.UUIDv4 helpers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StringSchema
    participant isPkg as internals/is

    User->>StringSchema: Validate email string
    StringSchema->>isPkg: Email(input)
    isPkg-->>StringSchema: bool (is valid?)
    StringSchema-->>User: Validation result

    User->>StringSchema: Validate UUIDv4 string
    StringSchema->>isPkg: UUIDv4(input)
    isPkg-->>StringSchema: bool (is valid?)
    StringSchema-->>User: Validation result
Loading

Assessment against linked issues

Objective Addressed Explanation
Email validation should fail for malformed emails (e.g., "email@email") and align with stricter standards (#160)

Poem

A regex hop, a bunny leap,
Through emails valid, and those too deep.
UUIDs checked with whisker-twitch,
No more bugs to make us itch!
With tests to guard each rabbit hole,
Our validation’s on a roll!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 557efdd and 4c48721.

📒 Files selected for processing (1)
  • internals/is/regex.go (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch fix/email-regex
  • Post Copyable Unit Tests in Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
internals/is/regex.go (1)

9-10: Case-sensitivity of email & UUID patterns

Both patterns accept only lowercase hex / ASCII letters.
For UUIDs a simple (?i) prefix ((?i)^[0-9a-f]{8}…) avoids rejecting valid uppercase strings without an extra strings.ToLower allocation.

string.go (1)

8-11: Import alias now unused

After delegating email/UUID checks to internals/is, the local alias p "github.com/Oudwins/zog/internals" remains the only aliased import; verify it is still necessary in this file. If not, drop the alias to keep import section clean.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5de48a3 and 557efdd.

📒 Files selected for processing (3)
  • internals/is/regex.go (1 hunks)
  • internals/is/regex_test.go (1 hunks)
  • string.go (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
string.go (1)
internals/is/regex.go (2)
  • Email (14-16)
  • UUIDv4 (18-20)
internals/is/regex_test.go (1)
internals/is/regex.go (2)
  • Email (14-16)
  • UUIDv4 (18-20)
🪛 GitHub Actions: ci
internals/is/regex_test.go

[error] 152-152: TestUUIDv4 failed: Expected true but was false for multiple UUID values, indicating invalid UUID validation.

🔇 Additional comments (2)
string.go (2)

213-216: Delegation looks good

Switching to is.Email centralises validation and removes duplicated regexes – ✔️


318-319: See comment on UUID regex

This call inherits the stricter v4-only behaviour. Ensure it matches the intended contract before release to avoid silent breaking change.

Comment on lines +137 to +144
validUUIDs := []string{
"9491d710-3185-4e06-bea0-6a2f275345e0",
"d89e7b01-7598-ed11-9d7a-0022489382fd",
"00000000-0000-0000-0000-000000000000",
"b3ce60f8-e8b9-40f5-1150-172ede56ff74",
"92e76bf9-28b3-4730-cd7f-cb6bc51f8c09",
}

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

“validUUIDs” contains non-v4 & invalid entries – tests are red

00000000-0000-0000-0000-000000000000 (version 0) and
d89e7b01-7598-ed11-… / b3ce60f8-e8b9-40f5-1150-… (variant/version mismatch) do not satisfy the v4 regex, causing CI failure.

Action items:

-validUUIDs := []string{
-    "9491d710-3185-4e06-bea0-6a2f275345e0",
-    "d89e7b01-7598-ed11-9d7a-0022489382fd",
-    "00000000-0000-0000-0000-000000000000",
-    "b3ce60f8-e8b9-40f5-1150-172ede56ff74",
-    "92e76bf9-28b3-4730-cd7f-cb6bc51f8c09",
-}
+validUUIDs := []string{
+    "9491d710-3185-4e06-bea0-6a2f275345e0",
+    "92e76bf9-28b3-4730-8d7f-cb6bc51f8c09", // adjust to v4
+}
+
+invalidUUIDs = append(invalidUUIDs,
+    "d89e7b01-7598-ed11-9d7a-0022489382fd",
+    "00000000-0000-0000-0000-000000000000",
+    "b3ce60f8-e8b9-40f5-1150-172ede56ff74")

Or, if all versions should be accepted, update the production regex accordingly (see comment in regex.go).

📝 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
validUUIDs := []string{
"9491d710-3185-4e06-bea0-6a2f275345e0",
"d89e7b01-7598-ed11-9d7a-0022489382fd",
"00000000-0000-0000-0000-000000000000",
"b3ce60f8-e8b9-40f5-1150-172ede56ff74",
"92e76bf9-28b3-4730-cd7f-cb6bc51f8c09",
}
validUUIDs := []string{
"9491d710-3185-4e06-bea0-6a2f275345e0",
"92e76bf9-28b3-4730-8d7f-cb6bc51f8c09", // adjust to v4
}
invalidUUIDs = append(invalidUUIDs,
"d89e7b01-7598-ed11-9d7a-0022489382fd",
"00000000-0000-0000-0000-000000000000",
"b3ce60f8-e8b9-40f5-1150-172ede56ff74")
🤖 Prompt for AI Agents
In internals/is/regex_test.go around lines 137 to 144, the validUUIDs slice
includes UUIDs that are not version 4 or are invalid, causing test failures. To
fix this, replace the entries with only valid version 4 UUIDs that match the v4
regex pattern. Alternatively, if the intention is to accept all UUID versions,
update the production regex in regex.go to match all valid UUID versions
accordingly.

@Oudwins Oudwins merged commit 954de17 into master Jun 14, 2025
8 checks passed
@Oudwins Oudwins deleted the fix/email-regex branch June 14, 2025 17:22
Oudwins added a commit that referenced this pull request Oct 3, 2025
* fix: regex for email

* fix: uuid regex

* fix: naming
Oudwins added a commit that referenced this pull request Dec 14, 2025
* fix: regex for email

* fix: uuid regex

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Email validation will pass on malformed email string

1 participant