From c3e24c1228b90c88c308b596753ff58d7c711045 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 31 Mar 2014 17:59:28 +0100 Subject: [PATCH] Trim spaces from new field and tag names Fixes #517 --- core/modules/widgets/fieldmangler.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/modules/widgets/fieldmangler.js b/core/modules/widgets/fieldmangler.js index cb9dc82c8..d902e755a 100644 --- a/core/modules/widgets/fieldmangler.js +++ b/core/modules/widgets/fieldmangler.js @@ -74,7 +74,7 @@ FieldManglerWidget.prototype.handleAddFieldEvent = function(event) { var tiddler = this.wiki.getTiddler(this.mangleTitle), fieldValidatorRegEx = /^[a-z\-\._]+$/mg; if(tiddler && typeof event.param === "string") { - var name = event.param.toLowerCase(); + var name = event.param.toLowerCase().trim(); if(name !== "" && !$tw.utils.hop(tiddler.fields,name)) { if(!fieldValidatorRegEx.test(name)) { alert($tw.language.getString( @@ -112,11 +112,14 @@ FieldManglerWidget.prototype.handleRemoveTagEvent = function(event) { FieldManglerWidget.prototype.handleAddTagEvent = function(event) { var tiddler = this.wiki.getTiddler(this.mangleTitle); - if(tiddler && typeof event.param === "string" && event.param !== "") { - var modification = this.wiki.getModificationFields(); - modification.tags = (tiddler.fields.tags || []).slice(0); - $tw.utils.pushTop(modification.tags,event.param); - this.wiki.addTiddler(new $tw.Tiddler(tiddler,modification)); + if(tiddler && typeof event.param === "string") { + var tag = event.param.trim(); + if(tag !== "") { + var modification = this.wiki.getModificationFields(); + modification.tags = (tiddler.fields.tags || []).slice(0); + $tw.utils.pushTop(modification.tags,tag); + this.wiki.addTiddler(new $tw.Tiddler(tiddler,modification)); + } } return true; };