Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong length in ValidURL RegEx for Top Level Domain part #259

Closed
rolman243 opened this issue Aug 24, 2024 · 0 comments · Fixed by #260
Closed

Wrong length in ValidURL RegEx for Top Level Domain part #259

rolman243 opened this issue Aug 24, 2024 · 0 comments · Fixed by #260
Labels
bug Something isn't working

Comments

@rolman243
Copy link
Contributor

rolman243 commented Aug 24, 2024

Describe the bug
Scala environment: JVM
Scala version: 3.4.2
Iron version: 2.6.0

Reproduction steps
The steps to reproduce the described issue

import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.string.ValidURL

opaque type Url <: String :| ValidURL = String :| ValidURL

object Url extends RefinedTypeOps[String, ValidURL, Url]

Url.applyUnsafe("https://aaaaa-bbb-cccccc-dddddddd.eeeeeeee-fff.ggg.hhhhhhhhh:1234")

The above code throws an IllegalArgumentException

Expected behavior
Url.applyUnsafe("https://aaaaa-bbb-cccccc-dddddddd.eeeeeeee-fff.ggg.hhhhhhhhh:1234") should not throw an exception.

The following regex for ValidURL fixes the problem:

"((\\w+:)+\\/\\/)?(([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,63})|(localhost))(:\\d{1,5})?(\\/|\\/([-a-zA-Z0-9@:%_\\+.~#?&//=]*))?"

Current behavior
According to mozilla the length of a top level domain allows up to 63 characters. The current ValidURL regex allows 6 characters only.
This results in false positives when checking valid URLs with more than 6 characters for a top level domain

@rolman243 rolman243 added the bug Something isn't working label Aug 24, 2024
Iltotore pushed a commit that referenced this issue Aug 24, 2024
Fix for Issue #259

Co-authored-by: Roland Manfrahs <[email protected]>
@Iltotore Iltotore linked a pull request Aug 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants