From a21967518c8b725dfe3505f41f96a653232b3760 Mon Sep 17 00:00:00 2001 From: Jesse van Herk Date: Sun, 21 Apr 2024 19:13:13 -0600 Subject: [PATCH] Fix browsing file names with percent-encoded @ This adds an encode method into the javascript code so that users can browser the Godot docs for @GlobalScope and @GDScript. The bug was mentioned in: https://github.com/freeCodeCamp/devdocs/pull/1853 This adds the encoding on the frontend, rather than trying to override filename generation in scrapers. It's possible that this will impact other documentation sources, but I expect those would also need to have encoded the @ as %40 in their own docs. This doesn't use JS' encodeURI or encodeURIComponent because encodeURI doesn't include @, and encodeURIComponent includes / which we don't want. If there are other URL-reserved characters that would be useful to encode, those should be easy enough to add to the short method added here. --- assets/javascripts/models/doc.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/models/doc.js b/assets/javascripts/models/doc.js index 53d573cde2..7e4d531c1f 100644 --- a/assets/javascripts/models/doc.js +++ b/assets/javascripts/models/doc.js @@ -71,9 +71,14 @@ app.models.Doc = class Doc extends app.Model { return this.entry; } + encodePath(path) { + return path.replace(/@/g, "%40"); + } + findEntryByPathAndHash(path, hash) { let entry; - if (hash && (entry = this.entries.findBy("path", `${path}#${hash}`))) { + let encodedPath = this.encodePath(path); + if (hash && (entry = this.entries.findBy("path", `${encodedPath}#${hash}`))) { return entry; } else if (path === "index") { return this.toEntry();