hapijs / hapijs/joi

String uri domain option does not allow Unicode when option is enabled

Open
#3,068 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

### Runtime

node.js

### Runtime version

v23.7.0

### Module version

17.13.3

### Last module version without issue

_No response_

### Used with

express

### Any other relevant information

I found this issue: https://github.com/hapijs/joi/issues/2889

Which introduced `encodeUri`. But this option can't be used (while it is [documented](https://joi.dev/api/?v=17.13.3#stringurioptions)).

Is this a regression?

### What are you trying to achieve or the steps to reproduce?

From what I understand, I should be able to use the `domain` option to validate URIs that contain Unicode characters (IDN):
https://joi.dev/api/?v=17.13.3#stringurioptions

For example:
```ts
Joi.object({
url: Joi.string().uri({
allowRelative: false,
domain: {
allowUnicode: true,
tlds: false,
}
})
})
```

But that does not work. Am I doing something wrong, or is this indeed a bug?

### What was the result you got?

Schema:
```ts
Joi.object({
url: Joi.string().uri({
allowRelative: false,
domain: {
allowUnicode: true,
tlds: false,
}
})
})
```

Data to validate:
```
{
url: "https://ëxample.com"
}
```

Output:
```
{
"url" /* "url" must be a valid uri */: "https://ëxample.com"
}
```

Sandbox reproduction:

![Image](https://github.com/user-attachments/assets/9d23b936-7c73-4f3c-9c8f-4fc52023ee47)

### What result did you expect?

For it to validate URIs that contain IDN, when the `allowUnicode` domain option is enabled.

IOW: for it to behave like [domain](https://joi.dev/api/?v=17.13.3#stringdomainoptions) (which does work as expected)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.