Module: Hyrax::RedirectPathNormalizer

Defined in:
app/services/hyrax/redirect_path_normalizer.rb

Overview

Normalizes a user- or system-supplied redirect path into the canonical form stored in hyrax_redirect_paths and queried by the resolver. Single source of truth for "what does this path look like on disk?".

Normalization rules:

  1. If input parses as a URL with scheme/host, keep only the path component (drop scheme, host, port, userinfo, query, fragment).
  2. Strip query strings and fragments from path-only inputs.
  3. Ensure a leading slash.
  4. Strip trailing slashes (but never reduce the path to empty).

Idempotent: normalize(normalize(x)) == normalize(x).

See documentation/redirects.md.

Class Method Summary collapse

Class Method Details

.call(input) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/hyrax/redirect_path_normalizer.rb', line 21

def call(input)
  return input if input.nil?
  path = input.to_s.strip
  return path if path.empty?

  path = extract_path(path)
  path = strip_query_and_fragment(path)
  path = ensure_leading_slash(path)
  path = strip_trailing_slashes(path)
  path
end