Browse Source

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

pull/195/head
Simon Eisenmann 11 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
$scope.newRoomName = ""; $scope.newRoomName = "";
}; };
//console.log("roomBar directive link", arguments);
//$scope.layout.roombar = true;
$scope.save = function() { $scope.save = function() {
if ($scope.roombarform.$invalid) { if ($scope.roombarform.$invalid) {
return; return;
} }
var roomName = rooms.joinByName($scope.newRoomName); var roomName = rooms.joinByName($scope.newRoomName);
if (roomName !== $scope.currentRoomName) { 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(); $scope.roombarform.$setPristine();
} }
}; };

22
static/js/services/resturl.js

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

17
static/js/services/rooms.js

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

Loading…
Cancel
Save