Skip to content

Commit 41ce7b6

Browse files
feat(core): Allow users to load data: URLs
Allows users to override the safety mechanism in the loader to load settings profiles from data URLs.
1 parent 1ac762a commit 41ce7b6

File tree

1 file changed

+8
-3
lines changed
  • packages/kitten-scientists/source/state

1 file changed

+8
-3
lines changed

packages/kitten-scientists/source/state/State.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { StateLoader } from "./StateLoader.js";
55
import { StateMerger } from "./StateMerger.js";
66

77
export class State extends TreeNode<State> {
8+
static ALLOW_DATA_URL_IMPORT = false;
9+
810
readonly originUrl: string;
911

1012
readonly loader: StateLoader;
@@ -16,9 +18,12 @@ export class State extends TreeNode<State> {
1618
constructor(originUrl: string, parent?: State) {
1719
super(parent);
1820
if (!originUrl.startsWith("https://kitten-science.com/")) {
19-
throw new InvalidOperationError(
20-
"While state import is experimental, you can only import from 'https://kitten-science.com/'!",
21-
);
21+
// Make an exception for data URLs, if the exception was explicitly allowed.
22+
if (!originUrl.startsWith("data:") || !State.ALLOW_DATA_URL_IMPORT) {
23+
throw new InvalidOperationError(
24+
"While state import is experimental, you can only import from 'https://kitten-science.com/'!",
25+
);
26+
}
2227
}
2328

2429
this.originUrl = originUrl;

0 commit comments

Comments
 (0)