sanity-io/sanity

URL Validation - allowRelative ignored when scheme doesn't include "http"

Opened this issue · 0 comments

Describe the bug

The allowRelative option is ignored when http isn't present in the list of schemes

To Reproduce

Define a field as follows:

{
  name: 'url',
  title: 'URL',
  type: 'url',
  validation: Rule => 
    Rule.uri({
      scheme: ['https'],
      allowRelative: true,
    }),
}

Then in that field, enter a relative URL such as /example - this will trigger a validation error of "Does not match allowed protocols/schemes".

The following code works as expected:

{
  name: 'url',
  title: 'URL',
  type: 'url',
  validation: Rule => 
    Rule.uri({
      scheme: ['http', 'https'],
      allowRelative: true,
    }),
}

Expected behavior

This should not cause a validation error.

Screenshots

Screenshot 2024-09-30 at 1 26 25 PM

Which versions of Sanity are you using?

@sanity/cli (global)        3.58.0 (up to date)
@sanity/cli                 3.58.0 (up to date)
@sanity/code-input           4.1.4 (up to date)
@sanity/color-input          4.0.1 (up to date)
@sanity/components          2.14.0 (up to date)
@sanity/dashboard            4.0.0 (up to date)
@sanity/icons                3.4.0 (up to date)
@sanity/production-preview  2.35.3 (up to date)
@sanity/vision              3.58.0 (up to date)
sanity                      3.58.0 (up to date)

What operating system are you using?
macOS 14.6.1 (23G93)

Which versions of Node.js / npm are you running?

  • NPM v10.7.0
  • Node v20.15.1