apache / apache/grails-core

Url validator doesn't accept localhost with port

Open
#10,249 5 comments 0 reactions 0 assignees View on GitHub
status: acknowledged type: improvement
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
### Steps to Reproduce
1. Create `url` validator for domain class string attribute.
2. Use localhost url with port, i.e. http://localhost:80.
3. Validate the domain class instance.
### Expected Behavior

I expect to have the localhost url with port valid. As a workaround, I've implemented custom validator with apache url validator.

```
import org.apache.commons.validator.routines.UrlValidator

validator: { val, obj ->
if (val) {
def urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS)
if (!urlValidator.isValid(val)) {
return "typeMismatch.java.net.URL"
}
}
}
```
### Actual Behavior

It fails in validation, error message `url.invalid`.
### Environment Information
- **Operating System**: OS X 10.11.6
- **Grails Version:** 3.2.0
- **JDK Version:** 1.8.0_77
- **Container Version (If Applicable):** n/a
### Example Application

https://github.com/kuceram/url-validation

Contributor guide

Open the contributing guide

Research direction

Start with the Grails URL validator behavior described in the issue and reproduce it using the linked kuceram/url-validation example application. Trace how `http://localhost:80` is handled, then verify that localhost URLs with ports are accepted without breaking existing URL validation cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.