Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
add url validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jspenguin2017 committed May 6, 2018
1 parent 84ac23a commit ad898cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
"webRequest",
"webRequestBlocking"
],
"version": "14.8"
"version": "14.9"
}
29 changes: 21 additions & 8 deletions src/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ const appName = (() => {
return manifest.name + " " + manifest.version;
})();

/**
* Show a specific error message.
* @function
* @param {string} msg - The message to show
*/
const showError = (msg) => {
$("#msg-specific-error p").text(msg);
$("#msg-specific-error").addClass("open");
};


$("#details").on("input", updateDetailsLimit);
updateDetailsLimit();
Expand All @@ -58,19 +68,22 @@ $("#send").on("click", async () => {
const details = $("#details").prop("value");

if (!category) {
$("#msg-specific-error p").text("You must choose a category.");
$("#msg-specific-error").addClass("open");
showError("You must choose a category.");
return;
}
if (!url) {
$("#msg-specific-error p").text("You must fill the URL field.");
$("#msg-specific-error").addClass("open");
if (
!url || !/^https?:/.test(url) ||
// Whitelist extension stores
url.startsWith("https://chrome.google.com/") ||
url.startsWith("https://www.microsoft.com/") ||
url.startsWith("https://addons.mozilla.org/")
) {
showError("You must enter a valid URL.");
return;
}
if (details.length > detailsLimit) {
$("#msg-specific-error p").text("Additional details can be at most "
+ detailsLimit.toString() + " characters long.");
$("#msg-specific-error").addClass("open");
showError("Additional details can be at most " +
detailsLimit.toString() + " characters long.");
return;
}

Expand Down

0 comments on commit ad898cd

Please sign in to comment.