Re: [w3c/manifest] Add id member to manifest (#988)

@dmurph commented on this pull request.



> +          <li>Set |manifest|["id"] to |manifest|["start_url"].
+          </li>
+          <li>If the type of |json|["id"] is not [=string=], return.
+          </li>
+          <li>Let |id:URL| be the result of [=URL Parser|parsing=] |json|["id"]
+          with |manifest|["start_ur"]'s origin as the base URL.
+          </li>
+          <li>If |id| is not same origin as |manifest|["start_url"], return.
+          </li>
+          <li>If |id| is failure, return.

Maybe more like:
```js
/**
 * @param {Object} json
 * @param {Map<string, any>} manifest
 */
 function processIdMember(json, manifest) {
  const startURL = manifest.get("start_url");
  const fallbackId = new URL(startURL);
  if (typeof json.id !== "string") {
    manifest.set("id", fallbackId);
    return;
  }

  // Maye we need to parse the json id as a url first?
  if (json.id.origin !== startURL.origin) {
    manifest.set("id", fallbackId);
    return;
  }

  let id;
  try {
      id = new URL(json.id, startURL.origin);
   } catch {
      id = fallbackId;
   }

  // finally, we have the id...
  manifest.set("id", id);
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/manifest/pull/988#discussion_r685326627

Received on Monday, 9 August 2021 16:05:07 UTC