nerdgram1337 1.6.0 → 1.7.5

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.
@@ -1,12 +1,49 @@
1
1
  // server/src/diagramLinks.ts
2
2
  var DIAGRAM_SCHEME = /^(nerdgram|diagram):/i;
3
3
  var ANY_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
4
+ var SAFE_HTTP = /^https?:$/i;
4
5
  function isDiagramLink(url) {
5
6
  if (!url || url.startsWith("//")) return false;
6
7
  if (ANY_SCHEME.test(url) && !DIAGRAM_SCHEME.test(url)) return false;
7
8
  const pathPart = url.split(/[?#]/)[0] ?? "";
8
9
  return DIAGRAM_SCHEME.test(url) || /\.mmd$/i.test(pathPart) || pathPart.startsWith("./") || pathPart.includes("/");
9
10
  }
11
+ function hasControlCharacter(value) {
12
+ for (let index = 0; index < value.length; index += 1) {
13
+ const code = value.charCodeAt(index);
14
+ if (code < 32 || code === 127) return true;
15
+ }
16
+ return false;
17
+ }
18
+ function clickTargetKind(raw) {
19
+ const url = raw.trim();
20
+ if (!url) return "none";
21
+ if (url.startsWith("//") || hasControlCharacter(url)) return "unsafe";
22
+ const squashed = url.replace(/[\u0000-\u0020]+/g, "").toLowerCase();
23
+ if (squashed.startsWith("javascript:") || squashed.startsWith("vbscript:") || squashed.startsWith("data:")) {
24
+ return "unsafe";
25
+ }
26
+ if (DIAGRAM_SCHEME.test(url)) return "diagram";
27
+ const scheme = ANY_SCHEME.exec(url);
28
+ if (scheme) {
29
+ const safe = safeHttpUrl(url);
30
+ return safe ? "external" : "unsafe";
31
+ }
32
+ return isDiagramLink(url) ? "diagram" : "none";
33
+ }
34
+ function safeHttpUrl(raw) {
35
+ const trimmed = raw.trim();
36
+ if (!trimmed || hasControlCharacter(trimmed) || trimmed.startsWith("//")) return null;
37
+ let parsed;
38
+ try {
39
+ parsed = new URL(trimmed);
40
+ } catch {
41
+ return null;
42
+ }
43
+ if (!SAFE_HTTP.test(parsed.protocol)) return null;
44
+ if (parsed.username || parsed.password) return null;
45
+ return parsed.toString();
46
+ }
10
47
  function parentPath(filePath) {
11
48
  const parts = filePath.replace(/\\/g, "/").split("/").filter(Boolean);
12
49
  parts.pop();
@@ -84,6 +121,7 @@ function parseClickLine(line, lineStart, lineNo) {
84
121
 
85
122
  export {
86
123
  isDiagramLink,
124
+ clickTargetKind,
87
125
  resolveDiagramTarget,
88
126
  diagramTargetExists,
89
127
  parseClickLine