mamute
mamute copied to clipboard
Bug on TagValidator
When editing a question, always error occurs validating the tags even when nothing is changed in them. (guj.com.br)
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
.
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.
guj.com.br is using ' ' (blank space) separator.
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));
}
}