oidc-caep-client 0.2.5 → 0.2.6-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/discovery.js +13 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oidc-caep-client",
3
- "version": "0.2.5",
3
+ "version": "0.2.6-next.0",
4
4
  "description": "In-browser OpenID Connect public client (PKCE, PAR, DPoP, RFC 9207) with token caching/auto-refresh and a Shared Signals (SSF) / CAEP event receiver",
5
5
  "homepage": "https://rcbj.github.io/oidc-caep-client/",
6
6
  "repository": {
package/src/discovery.js CHANGED
@@ -3,12 +3,23 @@ import { ValidationError } from './errors.js';
3
3
 
4
4
  const cache = new Map();
5
5
 
6
+ /**
7
+ * `s` without its trailing slashes. A loop, not `replace(/\/+$/, '')`: that regex is retried at every
8
+ * slash of a run that is not at the end, so a long run followed by any other character is quadratic.
9
+ * @param {string} s
10
+ */
11
+ function trimTrailingSlashes(s) {
12
+ let end = s.length;
13
+ while (end > 0 && s.charCodeAt(end - 1) === 0x2f) end--;
14
+ return s.slice(0, end);
15
+ }
16
+
6
17
  /**
7
18
  * Builds the OpenID Connect Discovery 1.0 §4 URL: the well-known suffix is appended to the issuer.
8
19
  * @param {string} issuer
9
20
  */
10
21
  export function oidcDiscoveryUrl(issuer) {
11
- return `${issuer.replace(/\/+$/, '')}/.well-known/openid-configuration`;
22
+ return `${trimTrailingSlashes(issuer)}/.well-known/openid-configuration`;
12
23
  }
13
24
 
14
25
  /**
@@ -19,7 +30,7 @@ export function oidcDiscoveryUrl(issuer) {
19
30
  */
20
31
  export function wellKnownUrls(issuer, suffix) {
21
32
  const u = new URL(issuer);
22
- const path = u.pathname.replace(/\/+$/, '');
33
+ const path = trimTrailingSlashes(u.pathname);
23
34
  const inserted = `${u.origin}/.well-known/${suffix}${path}`;
24
35
  const appended = `${u.origin}${path}/.well-known/${suffix}`;
25
36
  return inserted === appended ? [inserted] : [inserted, appended];