Browse Source

Strip spurious slashes and white space in path segments of room names.

pull/195/head
Simon Eisenmann 10 years ago
parent
commit
37ce3c6bfa
  1. 8
      static/js/directives/roombar.js
  2. 22
      static/js/services/resturl.js
  3. 17
      static/js/services/rooms.js

8
static/js/directives/roombar.js

@ -32,15 +32,17 @@ define(['underscore', 'angular', 'text!partials/roombar.html'], function(_, angu @@ -32,15 +32,17 @@ define(['underscore', 'angular', 'text!partials/roombar.html'], function(_, angu
$scope.newRoomName = "";
};
//console.log("roomBar directive link", arguments);
//$scope.layout.roombar = true;
$scope.save = function() {
if ($scope.roombarform.$invalid) {
return;
}
var roomName = rooms.joinByName($scope.newRoomName);
if (roomName !== $scope.currentRoomName) {
// Room name accepted.
$scope.roombarform.$setPristine();
} else {
// Room name did not apply. Reset new name and form.
$scope.newRoomName = roomName;
$scope.roombarform.$setPristine();
}
};

22
static/js/services/resturl.js

@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
*/
"use strict";
define(["underscore"], function(_) {
define(["underscore", "jquery"], function(_, $) {
// restURL
return ["globalContext", "$window", function(context, $window) {
@ -35,24 +35,34 @@ define(["underscore"], function(_) { @@ -35,24 +35,34 @@ define(["underscore"], function(_) {
RestURL.prototype.api = function(path) {
return (context.Cfg.B || "/") + "api/v1/" + path;
};
RestURL.prototype.encodeRoomURL = function(name, prefix) {
RestURL.prototype.encodeRoomURL = function(name, prefix, cb) {
// Split parts so slashes are allowed.
var parts = name.split("/");
var url = [];
var nn = [];
if (typeof prefix !== "undefined") {
url.push(prefix);
}
// Allow some thing in room name parts.
// Allow some things in room name parts.
_.each(parts, function(p) {
if (p === "") {
// Skip empty parts, effectly stripping spurious slashes.
return;
}
// Trim parts. removing white space from start and end.
p = $.trim(p);
nn.push(p);
// URL encode.
p = $window.encodeURIComponent(p);
// Encode back certain stuff we allow.
p = p.replace(/^%40/, "@");
p = p.replace(/^%24/, "$");
p = p.replace(/^%2B/, "+");
url.push(p);
});
if (url.length > 1 && url[url.length-1] === "") {
// Remove trailing slash if any.
url.pop();
if (cb) {
cb(url.join("/"));
return nn.join("/");
}
return url.join("/");
};

17
static/js/services/rooms.js

@ -212,15 +212,16 @@ define([ @@ -212,15 +212,16 @@ define([
return canJoinRooms;
},
joinByName: function(name, replace) {
var url = restURL.encodeRoomURL(name, "");
// Apply new URL.
safeApply($rootScope, function(scope) {
$location.path(url);
if (replace) {
$location.replace();
}
var nn = restURL.encodeRoomURL(name, "", function(url) {
// Apply new URL.
safeApply($rootScope, function(scope) {
$location.path(url);
if (replace) {
$location.replace();
}
});
});
return name;
return nn;
},
joinDefault: function(replace) {
return rooms.joinByName("", replace);

Loading…
Cancel
Save