Permalink
Browse files

Escape "/" which causes rhc web server URL matching confusing

Signed-off-by: Eric Miao <eric.y.miao@gmail.com>
  • Loading branch information...
ericmiao committed Apr 6, 2014
1 parent 800a5d3 commit 4e91836909561fbcf0a7d8e715b3599bc6dcdd4d
Showing with 15 additions and 6 deletions.
  1. +8 −3 core/modules/commands/server.js
  2. +7 −3 plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js
@@ -25,6 +25,10 @@ exports.info = {
synchronous: true
};
function decodeTiddlerTitle(title) {
return decodeURIComponent(title).replace(/%SLASH%/g, "/");
}
/*
A simple HTTP server with regexp-based routes
*/
@@ -83,6 +87,7 @@ SimpleServer.prototype.listen = function(port,host) {
var self = this;
http.createServer(function(request,response) {
// Compose the state object
console.log("new request: " + request.url + " type=" + request.method);
var state = {};
state.wiki = self.wiki;
state.server = self;
@@ -144,7 +149,7 @@ var Command = function(params,commander,callback) {
method: "PUT",
path: /^\/recipes\/default\/tiddlers\/(.+)$/,
handler: function(request,response,state) {
var title = decodeURIComponent(state.params[0]),
var title = decodeTiddlerTitle(state.params[0]),
fields = JSON.parse(state.data);
// Pull up any subfields in the `fields` object
if(fields.fields) {
@@ -169,7 +174,7 @@ var Command = function(params,commander,callback) {
method: "DELETE",
path: /^\/bags\/default\/tiddlers\/(.+)$/,
handler: function(request,response,state) {
var title = decodeURIComponent(state.params[0]);
var title = decodeTiddlerTitle(state.params[0]);
state.wiki.deleteTiddler(title);
response.writeHead(204, "OK");
response.end();
@@ -233,7 +238,7 @@ var Command = function(params,commander,callback) {
method: "GET",
path: /^\/recipes\/default\/tiddlers\/(.+)$/,
handler: function(request,response,state) {
var title = decodeURIComponent(state.params[0]),
var title = decodeTiddlerTitle(state.params[0]),
tiddler = state.wiki.getTiddler(title),
tiddlerFields = {},
knownFields = [
@@ -15,6 +15,10 @@ A sync adaptor module for synchronising with TiddlyWeb compatible servers
var CONFIG_HOST_TIDDLER = "$:/config/tiddlyweb/host",
DEFAULT_HOST_TIDDLER = "$protocol$//$host$/";
function encodeTiddlerTitle(title) {
return encodeURIComponent(title.replace(/\//g, "%SLASH%"));
}
function TiddlyWebAdaptor(syncer) {
this.syncer = syncer;
this.host = this.getHost();
@@ -159,7 +163,7 @@ Save a tiddler and invoke the callback with (err,adaptorInfo,revision)
TiddlyWebAdaptor.prototype.saveTiddler = function(tiddler,callback) {
var self = this;
$tw.utils.httpRequest({
url: this.host + "recipes/" + encodeURIComponent(this.recipe) + "/tiddlers/" + encodeURIComponent(tiddler.fields.title),
url: this.host + "recipes/" + encodeURIComponent(this.recipe) + "/tiddlers/" + encodeTiddlerTitle(tiddler.fields.title),
type: "PUT",
headers: {
"Content-type": "application/json"
@@ -185,7 +189,7 @@ Load a tiddler and invoke the callback with (err,tiddlerFields)
TiddlyWebAdaptor.prototype.loadTiddler = function(title,callback) {
var self = this;
$tw.utils.httpRequest({
url: this.host + "recipes/" + encodeURIComponent(this.recipe) + "/tiddlers/" + encodeURIComponent(title),
url: this.host + "recipes/" + encodeURIComponent(this.recipe) + "/tiddlers/" + encodeTiddlerTitle(title),
callback: function(err,data,request) {
if(err) {
return callback(err);
@@ -208,7 +212,7 @@ TiddlyWebAdaptor.prototype.deleteTiddler = function(title,callback) {
}
// Issue HTTP request to delete the tiddler
$tw.utils.httpRequest({
url: this.host + "bags/" + encodeURIComponent(bag) + "/tiddlers/" + encodeURIComponent(title),
url: this.host + "bags/" + encodeURIComponent(bag) + "/tiddlers/" + encodeTiddlerTitle(title),
type: "DELETE",
callback: function(err,data,request) {
if(err) {

1 comment on commit 4e91836

@maibarra

This comment has been minimized.

maibarra commented on 4e91836 May 28, 2017

Is there a possibility that applying this diff actually breaks CSS display when applying this to this guide
Screenshot of this result:
midn

Please sign in to comment.