Skip to content

Commit 0612d9f

Browse files
committed
A readable link whose JSON breaks puts its text in the box, with where it breaks, for the chat to fix
1 parent 060d959 commit 0612d9f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/h5p/build/build-source.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export interface TypeFile {
3535
* model can write its own JSON but cannot compress it (h5p-offline-player#206). The value runs to
3636
* the end of the fragment, since JSON text holds `&` and `+`, and it is percent-decoded as far as
3737
* it can be (`percentDecoded`). Base64url never holds `{` or `%`, so the forms cannot be mistaken.
38+
* Its text is returned even where it is not JSON: a weak model's JSON slips, and text that can
39+
* be read goes in the box, where the build lists where the JSON breaks, for the chat to fix, as
40+
* for a source pasted in. Only a compressed source that cannot be read is a damaged link.
3841
*
3942
* Returns `null` for a fragment that carries none, and throws for one that carries something else.
4043
*/
@@ -46,8 +49,7 @@ export async function sourceFromFragment(hash: string): Promise<string | null> {
4649
if (isJson(text)) return text
4750
// A link set in a sentence may end in what follows it, as `}.`: the JSON is up to its last brace.
4851
const upToBrace = text.slice(0, text.lastIndexOf('}') + 1)
49-
if (isJson(upToBrace)) return upToBrace
50-
throw new Error('The link’s #source= holds JSON that does not parse')
52+
return isJson(upToBrace) ? upToBrace : text
5153
}
5254
const value = new URLSearchParams(fragment).get('source')
5355
if (!value) return null

0 commit comments

Comments
 (0)