Skip to content

Commit

Permalink
fix: embed.js link fixup when facing invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
rpj committed Jul 2, 2022
1 parent 4890068 commit ae71d2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions client/embed.js
Expand Up @@ -101,13 +101,20 @@ const keyMatchRegex = /83e(0[1-9]|1[0-2])(\d\d)$/;
function fixupBoardLinks (parentNode, contEleId, options) {
for (const child of parentNode.childNodes) {
if (child.tagName === 'A') {
const checkUrl = new URL(child.attributes.href.value);
if (!knownS83Hosts.includes(checkUrl.host)) {
let checkUrl;
try {
checkUrl = new URL(child.attributes.href.value);
} catch (err) {
// invalid URL, so nothing to fixup: skip
continue;
}

if (!knownS83Hosts.includes(checkUrl?.host)) {
return;
}

const s83Key = checkUrl.pathname.replace(/^\//, '');
if (s83Key.length !== 64) {
const s83Key = checkUrl?.pathname.replace(/^\//, '');
if (s83Key?.length !== 64) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion client/root.tmpl.html
Expand Up @@ -135,7 +135,7 @@ <h3>Publicly listed <span id="ttl">(time-to-live)</i>:</h3>
Additional un<a href="https://github.com/robinsloan/spring-83">specified</a> functionality provided:
<ul>
<li>Board <a href="https://github.com/rpj/spring83/blob/main/README.md#post-endpoint">minification & link shortening</a>.</li>
<li>A <a href="/embed.js">utility API</a> for embedding Springboards (w/ <a href="/embedded-json-example.html">embedded JSON extraction</a>).</li>
<li>A <a href="/embed.js">utility API</a> for embedding Springboards (w/ <a href="/embedded-json-example.html">JSON extraction</a>).</li>
<li><a href="https://github.com/rpj/spring83/blob/main/README.md#post-endpoint#qr-code-generation">QR code generation</a> for board public keys &amp; links to.</li>
</ul>
</p>
Expand Down

0 comments on commit ae71d2d

Please sign in to comment.