Skip to content

Commit e16c106

Browse files
committed
webinterface: fix gist user discovery requests
Since URL.path.bySegment returns [, run-dlang, <gist-id>] when the request path is '/run-dlang/<gist-id>', first value should be discarded if empty. Signed-off-by: Luís Ferreira <contact@lsferreira.net>
1 parent 35de8fc commit e16c106

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

source/webinterface.d

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class WebInterface
271271
sourceCode = Base64.encode(cast(ubyte[]) sourceCodeRaw);
272272
}
273273
auto googleAnalyticsId = googleAnalyticsId_;
274-
showEditor(sourceCode);
274+
showEditor(sourceCode);
275275
}
276276

277277
@path("/gist/:gist")
@@ -287,7 +287,17 @@ class WebInterface
287287
string user = "";
288288
auto location = URL(res.headers.get("Location", "https://gist.github.com/run-dlang")).path.bySegment;
289289
if (!location.empty)
290-
user = location.front.name;
290+
{
291+
auto first_loc = location.front.name;
292+
// skip first slash from path
293+
if(first_loc.empty) {
294+
location.popFront;
295+
user = location.front.name;
296+
}
297+
else {
298+
user = first_loc;
299+
}
300+
}
291301

292302
getGist(user, _gist);
293303
}
@@ -296,14 +306,14 @@ class WebInterface
296306
void getGist(string _user, string _gist)
297307
{
298308
import std.base64;
299-
auto sourceCode = requestHTTP("https://gist.githubusercontent.com/%s/%s/raw".format(_user, _gist))
300-
.bodyReader
301-
.readAllUTF8;
302-
showEditor(Base64.encode(sourceCode.representation));
309+
auto sourceCode = requestHTTP("https://gist.githubusercontent.com/%s/%s/raw".format(_user, _gist))
310+
.bodyReader
311+
.readAllUTF8;
312+
showEditor(Base64.encode(sourceCode.representation));
303313
}
304314

305315
void showEditor(string sourceCode) {
306-
string googleAnalyticsId = googleAnalyticsId_;
316+
string googleAnalyticsId = googleAnalyticsId_;
307317
const title = "Online D Editor";
308318
const chapterId = "";
309319
const language = "en";

0 commit comments

Comments
 (0)