mamute icon indicating copy to clipboard operation
mamute copied to clipboard

Bug on TagValidator

Open douglasjunior opened this issue 9 years ago • 3 comments

When editing a question, always error occurs validating the tags even when nothing is changed in them. (guj.com.br) captura de tela 2015-05-19 as 17 05 39

I think the problem is the regular expression validation.

tags.sanitizer.regex = [a-zA-Z0-9-]

https://github.com/caelum/mamute/blob/48321d522612a24a07c53691a15fab4058b2a3a0/src/main/resources/mamute.properties#L18

When does the replace, it does not remove the commas of the tags, so it falls in the exception. https://github.com/caelum/mamute/blob/1d62cafe0037dfa9174845346e47b0d286f173e9/src/main/java/org/mamute/validators/TagsValidator.java#L39

Apparently the bug appeared in this commit: https://github.com/caelum/mamute/commit/30ede66930e2b03e163d606cb77ea03c8a943616

Or can also be in TagsSplitter.

douglasjunior avatar May 20 '15 11:05 douglasjunior

The problem actually is on the javascript. Right now the char that split tags is configurable through mamute.properties (tags.splitter.regex and tags.splitter.char), but the jquery plugin that we use for the tags input widget works only with ',' char to split tags. I guess this is broken since https://github.com/caelum/mamute/commit/5ba6d75d61886ce00f73d78d9a121f0e65729647

I think we would need to customise this plugin to make it configurable. As a quick workaround we could simply remove these two properties and force all users to use ',' as the separator of tags. I think this won't be a problem since guj.com.br should be only site using this configuration.

csokol avatar Jun 05 '15 02:06 csokol

guj.com.br is using ' ' (blank space) separator.

csokol avatar Jun 05 '15 02:06 csokol

that makes more sense than my patch. but could you please look at it (below)? the issue that i was seeing is that the first submit of a new question gets "tag not found" error, even when env.supports("feature.tags.add.anyone"). then i submit a second time and it works (hence your solution makes more sense). but can you explain why the patch below is incorrect?

diff --git a/src/main/java/org/mamute/validators/TagsValidator.java b/src/main/java/org/mamute/validators/TagsValidator.java
index 4eec8ae..6769ffe 100644
--- a/src/main/java/org/mamute/validators/TagsValidator.java
+++ b/src/main/java/org/mamute/validators/TagsValidator.java
@@ -39,7 +39,7 @@ public class TagsValidator {
                        String replace = name.replaceAll(env.get("tags.sanitizer.regex"), "");
                        if (replace.length() != 0) {
                                validator.add(messageFactory.build("error", "tag.errors.illegal_char", name, replace));
-                       } else if (!isPresent(name, found)) {
+                       } else if (!isPresent(name, found) && !env.supports("feature.tags.add.anyone")) {
                                validator.add(messageFactory.build("error", "tag.errors.doesnt_exist", name));
                        }
                }

tomkast avatar Aug 17 '15 21:08 tomkast