From e01b78c1205bce61b7c63e4fd97b1829c2c1eb42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Wed, 21 Oct 2020 02:00:52 +0100 Subject: [PATCH 1/3] webinterface: fix gist user discovery requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since URL.path.bySegment returns [, run-dlang, ] when the request path is '/run-dlang/', first value should be discarded if empty. Signed-off-by: Luís Ferreira --- source/webinterface.d | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/source/webinterface.d b/source/webinterface.d index 1781740c..9173700a 100644 --- a/source/webinterface.d +++ b/source/webinterface.d @@ -271,7 +271,7 @@ class WebInterface sourceCode = Base64.encode(cast(ubyte[]) sourceCodeRaw); } auto googleAnalyticsId = googleAnalyticsId_; - showEditor(sourceCode); + showEditor(sourceCode); } @path("/gist/:gist") @@ -287,7 +287,17 @@ class WebInterface string user = ""; auto location = URL(res.headers.get("Location", "https://gist.github.com/run-dlang")).path.bySegment; if (!location.empty) - user = location.front.name; + { + auto first_loc = location.front.name; + // skip first slash from path + if(first_loc.empty) { + location.popFront; + user = location.front.name; + } + else { + user = first_loc; + } + } getGist(user, _gist); } @@ -296,14 +306,14 @@ class WebInterface void getGist(string _user, string _gist) { import std.base64; - auto sourceCode = requestHTTP("https://gist.githubusercontent.com/%s/%s/raw".format(_user, _gist)) - .bodyReader - .readAllUTF8; - showEditor(Base64.encode(sourceCode.representation)); + auto sourceCode = requestHTTP("https://gist.githubusercontent.com/%s/%s/raw".format(_user, _gist)) + .bodyReader + .readAllUTF8; + showEditor(Base64.encode(sourceCode.representation)); } void showEditor(string sourceCode) { - string googleAnalyticsId = googleAnalyticsId_; + string googleAnalyticsId = googleAnalyticsId_; const title = "Online D Editor"; const chapterId = ""; const language = "en"; From f2bd3a21bae6a5aedec84e4578e666e448fb37bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Sat, 24 Dec 2022 04:27:06 +0000 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Mathias LANG --- source/webinterface.d | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/webinterface.d b/source/webinterface.d index 9173700a..cf1d69e4 100644 --- a/source/webinterface.d +++ b/source/webinterface.d @@ -290,11 +290,10 @@ class WebInterface { auto first_loc = location.front.name; // skip first slash from path - if(first_loc.empty) { - location.popFront; + if (first_loc.empty) { + location.popFront(); user = location.front.name; - } - else { + } else { user = first_loc; } } From ea3df9dd33fa53f5fda81b144678728d706bf55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Sat, 24 Dec 2022 04:28:01 +0000 Subject: [PATCH 3/3] Update source/webinterface.d --- source/webinterface.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/webinterface.d b/source/webinterface.d index cf1d69e4..9791abf3 100644 --- a/source/webinterface.d +++ b/source/webinterface.d @@ -271,7 +271,7 @@ class WebInterface sourceCode = Base64.encode(cast(ubyte[]) sourceCodeRaw); } auto googleAnalyticsId = googleAnalyticsId_; - showEditor(sourceCode); + showEditor(sourceCode); } @path("/gist/:gist")