hapijs / hapijs/validate

string().hostname() does not allow FQDNs ending with a dot

Open
#20 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
2
Forks
11
PR merge metrics
No merged PRs in 30d

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: v12+
* *module version with issue*: v17
* *last module version without issue*: unknown
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*: This issue was originally reported by @kanongil in https://github.com/hapijs/validate/pull/19#issuecomment-708582209.

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

Validate any FQDN that includes a trailing dot.

```js
// Returns { error } as [Error [ValidationError]: "value" must be a valid hostname]
Validate.string().hostname().validate('www.hapi.dev.');
```

#### What was the result you got?

Validate does not allow the FQDN with a trailing dot to pass validation. Validation fails with a `ValidationError` `"value" must be a valid hostname`.

#### What result did you expect?

I would expect the FQDN with a trailing dot to validate without error. It is also worth noting that node's `server.listen()` does allow hostnames that include a trailing dot.

A note to the implementer: I believe trailing dots are only allowed for FQDNs, which means the input a. cannot be an IP address ~~, and b. must have at least three segments~~. In other words `192.168.1.1.` is not valid ~~and `hapi.dev.` is not valid (missing a hostname in the leftmost label)~~ (edited: see comment below).

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.