Skip to content

Commit 8d49d49

Browse files
committed
#29 - error message when server URL missing scheme
1 parent 7b4a70a commit 8d49d49

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/components/nsNextcloud.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ function wwwFormUrlEncode (aStr) {
5151
.replace(/\@/g, '%40');
5252
}
5353

54+
function validURL(value) {
55+
return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
56+
}
57+
5458
/**
5559
* Our Nextcloud Provider
5660
*/
5761
function Nextcloud () {
58-
//this.log = Log4Moz.getConfiguredLogger("Nextcloud", Log4Moz.Level.Info, Log4Moz.Level.Debug,
59-
// Log4Moz.Level.Debug);
62+
// this.log = Log4Moz.getConfiguredLogger("Nextcloud", Log4Moz.Level.Info, Log4Moz.Level.Debug,
63+
// Log4Moz.Level.Debug);
6064
this.log = Log4Moz.getConfiguredLogger("Nextcloud");
6165
}
6266

@@ -379,7 +383,7 @@ Nextcloud.prototype = {
379383
],
380384
2);
381385

382-
if (authPrompter.promptPassword(
386+
if (validURL(serverUrl) && authPrompter.promptPassword(
383387
this.displayName,
384388
promptString,
385389
serverUrl,
@@ -411,8 +415,15 @@ Nextcloud.prototype = {
411415
logon: function nsNc_logon (successCallback, failureCallback, aWithUI) {
412416
this.log.info("Logging in, aWithUI = " + aWithUI);
413417

414-
if (this._password == undefined || !this._password)
418+
if (this._password == undefined || !this._password) {
415419
this._password = this.getPassword(this._userName, !aWithUI);
420+
}
421+
422+
if (this._password == "") {
423+
this.log.error('Could not retrieve password');
424+
this._loggedIn = false;
425+
failureCallback();
426+
}
416427

417428
this.log.info("Sending login information...");
418429

0 commit comments

Comments
 (0)