GeoLeaf Core API - v3.0.0
    Preparing search index...
    • Validates a URL and returns it resolved.

      The protocol allow-list is the substance of the check: it is what keeps javascript: out of an attribute built from profile data. data: URLs are refused unless allowDataImages is set, and even then only image MIME types pass.

      On success the third field carries the resolved absolute URL, so a relative input comes back usable; on failure it is null.

      Parameters

      Returns { valid: boolean; error: string | null; url: string | null }

      { valid, error, url }, where url is the resolved absolute form or null.

      GeoLeafError A ValidationError when rejected and throwOnError is set.

      // URL HTTPS valide
      const result = GeoLeaf.Validators.validateUrl("https://example.com/data.json");
      // Returns: { valid: true, error: null, url: 'https://example.com/data.json' }

      // Protocole non autorisé
      const result2 = GeoLeaf.Validators.validateUrl("ftp://example.com/file");
      // Returns: { valid: false, error: 'Protocol "ftp:" not allowed', url: null }

      // Autoriser seulement HTTPS
      const result3 = GeoLeaf.Validators.validateUrl("http://example.com", {
      allowedProtocols: ["https:"],
      });
      // Returns: { valid: false, error: 'Protocol "http:" not allowed', url: null }