0

https://www.example.com/&audience=testingting?internal-abhishek-jwt=random_string

Is this a valid URL? i.e is it fine to have &audience first and ?internal-abhishek-jwt as the second query paramter?

Please note audience has & as prefix

Makyen
  • 31,849
  • 12
  • 86
  • 121

1 Answers1

1

Is this a valid URL?

The URL spec says that the path should be expressed per these rules:

  path          = path-abempty    ; begins with "/" or is empty
                / path-absolute   ; begins with "/" but not "//"
                / path-noscheme   ; begins with a non-colon segment
                / path-rootless   ; begins with a segment
                / path-empty      ; zero characters

  path-abempty  = *( "/" segment )
  path-absolute = "/" [ segment-nz *( "/" segment ) ]
  path-noscheme = segment-nz-nc *( "/" segment )
  path-rootless = segment-nz *( "/" segment )
  path-empty    = 0<pchar>
  segment       = *pchar
  segment-nz    = 1*pchar
  segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
                ; non-zero-length segment without any colon ":"

  pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

Which, to cut a long story short, allows the types of character defined on the last line in a segment (which is where you want to put your &).

And if we look at sub-delims:

 sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
             / "*" / "+" / "," / ";" / "="

… so & is allowed.


That said, it is highly unusual to see a & in a URL outside of a query string.

If you put one there then it is not unlikely that someone transcribing the URL will assume you made a mistake and change it … thus breaking it.

So they are best avoided.


i.e is it fine to have &audience first and ?internal-abhishek-jwt as the second query paramter?

No.

The ? starts the query string. Putting them in that order makes &audience part of the path.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335