Skip to content

Function: isDotSegment()

API / @xmachines/play-pattern / isDotSegment

function isDotSegment(segment): boolean;

Defined in: play-pattern/src/pattern-grammar.ts:872

Answers whether one segment resolves away in a URL, rather than naming itself.

A URL parser reads the dot segments BEFORE it decodes the percent escapes, and it counts %2e as the dot. The WHATWG URL standard names six forms, and a browser resolves every one of them out of a location: . and %2e for the single dot, and .., .%2e, %2e. and %2e%2e for the double dot. Each percent test is case-insensitive.

NO encoding of . or .. therefore survives. A param that carries one describes a path that its own pattern matches back never, so buildPath refuses it, and normalizeBasePath of @xmachines/play-url refuses the same value in a base path.

Give the segment in the form that the URL carries, and encode nothing here. The two callers reach that form by two roads, and both are correct. buildPath encodes a param value first, so a value that HOLDS a percent sign arrives with that sign escaped: the string "%2e" encodes to "%252e", which names itself and stays. normalizeBasePath of @xmachines/play-url reads a path that an author wrote, which is encoded already, so it passes the segment RAW and "%2e" there is the dot. A caller that encodes an already-encoded segment a second time hides every %2e from this test.

Parameters

ParameterTypeDescription
segmentstringONE path segment, with no separator around it, in the form that the URL carries it.

Returns

boolean

true when a URL resolves the segment away.