Skip to content

Commit

Permalink
Merge pull request #134 from CodeMyst/fix/language-edit
Browse files Browse the repository at this point in the history
You can't create a paste with an invalid language
  • Loading branch information
CodeMyst authored Mar 4, 2019
2 parents b050eaf + 5d701be commit 9cc6479
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
36 changes: 36 additions & 0 deletions public/languages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
autodetect
plaintext
bat
c
csharp
cpp
css
clojure
coffeescript
d
dockerfile
fsharp
go
html
handlebars
ini
json
java
javascript
lua
markdown
objective
php
perl
powershell
python
r
razor
ruby
rust
sql
swift
typescript
vb
xml
yaml
19 changes: 19 additions & 0 deletions source/pastemyst.d
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ PasteMystInfo createPaste (string code, string expiresIn, string language)
if (checkValidExpiryTime (expiresIn) == false)
throw new HTTPStatusException (400, "Invalid \"expiresIn\" value. Expected: never, 1h, 2h, 10h, 1d, 2d or 1w.");

if (checkValidLanguage (language) == false)
throw new HTTPStatusException (400, "Invalid \"language\" value.");

Connection connection = connectionPool.getConnection ();

string id;
Expand Down Expand Up @@ -452,6 +455,22 @@ unittest
assert (checkValidExpiryTime ("adsj98sdaj") == false);
}

bool checkValidLanguage (string language)
{
import std.file : readText, getcwd;
import std.string : splitLines;

string [] validLanguages = readText (getcwd () ~ "/public/languages.txt").splitLines ();

foreach (lang; validLanguages)
{
if (language == lang)
return true;
}

return false;
}

/++
Returns the appsettings.json
+/
Expand Down

0 comments on commit 9cc6479

Please sign in to comment.