3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Decode docs hash parts independently (#2620)
Veeramanikandanr48565ed5b0a6d3
diff --git a/changes/2620.md b/changes/2620.mdnew file mode 100644index 00000000..b13abc95--- /dev/null+++ b/changes/2620.md@@ -0,0 +1 @@+- A malformed percent escape in a docs URL hash no longer blanks the page; the bad part is treated as empty so the first topic opens (#2620)diff --git a/src/documentation-hash.js b/src/documentation-hash.jsnew file mode 100644index 00000000..023d74a1--- /dev/null+++ b/src/documentation-hash.js@@ -0,0 +1,13 @@+function decodeHashPart(part) {+ try {+ return decodeURIComponent(part);+ } catch {+ return '';+ }+}++/** The topic and section named by a docs hash; one bad escape only clears that part. */+export function parseDocumentationHash(hash) {+ const [topic = '', section = ''] = hash.replace(/^#/, '').split('/');+ return { topic: decodeHashPart(topic), section: decodeHashPart(section) };+}diff --git a/src/documentation.js b/src/documentation.jsindex f0626b10..f5a045e7 100644--- a/src/documentation.js+++ b/src/documentation.js@@ -5,6 +5,7 @@ import { highlightCode } from './code-highlight.js';import { createLiveExample, autoRunVisibleExamples } from './docs-live.js';import { createApiReference } from './docs-api.js';import { topicAliases, topicSlug, guideTopics, learnTopics, orderTopics } from './documentation-topics.js';+import { parseDocumentationHash } from './documentation-hash.js';const learnSources = import.meta.glob('../docs/learn/*.md', { query: '?raw', import: 'default', eager: true });@@ -348,7 +349,7 @@ function renderOutline(section) {}function parseHash() {- const [requestedTopic = '', requestedSection = ''] = decodeURIComponent(location.hash.slice(1)).split('/');+ const { topic: requestedTopic, section: requestedSection } = parseDocumentationHash(location.hash);return { hashTopic: requestedTopic, requestedTopic: topicAliases[requestedTopic] ?? requestedTopic, requestedSection };}diff --git a/tests/documentation-hash.test.js b/tests/documentation-hash.test.jsnew file mode 100644index 00000000..a59089db--- /dev/null+++ b/tests/documentation-hash.test.js@@ -0,0 +1,9 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { parseDocumentationHash } from '../src/documentation-hash.js';++test('a malformed percent escape in a docs hash clears only that part', () => {+ assert.deepEqual(parseDocumentationHash('#%E0%A4%A'), { topic: '', section: '' });+ assert.deepEqual(parseDocumentationHash('#mesh/edge%ZZ'), { topic: 'mesh', section: '' });+ assert.deepEqual(parseDocumentationHash('#mesh-blend/fog%20bounce'), { topic: 'mesh-blend', section: 'fog bounce' });+});