mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
83934: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 81657: Merged DEV to V4.2-BUG-FIX (4.2.4) 78463 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n chars should not be created 80398 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n and | chars should not be created 80403 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Replace bad \n and | characters to _ char patch 83538: MNT-12288 : Reverse Merge V4.2-BUG-FIX (4.2.4) << Caused upgrade failure as the patch relies on search >> 81657 : Merged DEV to V4.2-BUG-FIX (4.2.4) 78463 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n chars should not be created 80398 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n and | chars should not be created 80403 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Replace bad \n and | characters to _ char patch 83539: Merged DEV to V4.2-BUG-FIX (4.2.4) 78463 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n chars should not be created 80398 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n and | chars should not be created git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@84600 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -25,13 +25,16 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
@@ -73,6 +76,7 @@ import org.alfresco.service.namespace.QName;
|
|||||||
import org.alfresco.util.ISO9075;
|
import org.alfresco.util.ISO9075;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -109,6 +113,10 @@ public class TaggingServiceImpl implements TaggingService,
|
|||||||
|
|
||||||
/** Tag Details Delimiter */
|
/** Tag Details Delimiter */
|
||||||
private static final String TAG_DETAILS_DELIMITER = "|";
|
private static final String TAG_DETAILS_DELIMITER = "|";
|
||||||
|
/** Next tag delimiter */
|
||||||
|
private static final String NEXT_TAG_DELIMITER = "\n";
|
||||||
|
|
||||||
|
private static Set<String> FORBIDDEN_TAGS_SEQUENCES = new HashSet<String>(Arrays.asList(new String[] {NEXT_TAG_DELIMITER, TAG_DETAILS_DELIMITER}));
|
||||||
|
|
||||||
/** Policy behaviour */
|
/** Policy behaviour */
|
||||||
private JavaBehaviour updateTagBehaviour;
|
private JavaBehaviour updateTagBehaviour;
|
||||||
@@ -720,6 +728,14 @@ public class TaggingServiceImpl implements TaggingService,
|
|||||||
*/
|
*/
|
||||||
private NodeRef getTagNodeRef(StoreRef storeRef, String tag, boolean create)
|
private NodeRef getTagNodeRef(StoreRef storeRef, String tag, boolean create)
|
||||||
{
|
{
|
||||||
|
for (String forbiddenSequence : FORBIDDEN_TAGS_SEQUENCES)
|
||||||
|
{
|
||||||
|
if (create && tag.contains(forbiddenSequence))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Tag name must not contain " + StringEscapeUtils.escapeJava(forbiddenSequence) + " char sequence");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NodeRef tagNodeRef = null;
|
NodeRef tagNodeRef = null;
|
||||||
Collection<ChildAssociationRef> results = this.categoryService.getRootCategories(storeRef, ContentModel.ASPECT_TAGGABLE, tag, create);
|
Collection<ChildAssociationRef> results = this.categoryService.getRootCategories(storeRef, ContentModel.ASPECT_TAGGABLE, tag, create);
|
||||||
if (!results.isEmpty())
|
if (!results.isEmpty())
|
||||||
@@ -1314,7 +1330,7 @@ public class TaggingServiceImpl implements TaggingService,
|
|||||||
{
|
{
|
||||||
if (bFirst == false)
|
if (bFirst == false)
|
||||||
{
|
{
|
||||||
result.append("\n");
|
result.append(NEXT_TAG_DELIMITER);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -124,6 +124,9 @@ public class TaggingServiceImplTest extends TestCase
|
|||||||
private static final String TAG_5 = "tag five";
|
private static final String TAG_5 = "tag five";
|
||||||
private static final String TAG_I18N = "àâæçéèêëîïôœùûüÿñ";
|
private static final String TAG_I18N = "àâæçéèêëîïôœùûüÿñ";
|
||||||
|
|
||||||
|
private static final String BAD_TAG = "bad \n tag";
|
||||||
|
private static final String BAD_TAG2 = "Broken|2";
|
||||||
|
|
||||||
private static final String UPPER_TAG = "House";
|
private static final String UPPER_TAG = "House";
|
||||||
private static final String LOWER_TAG = "house";
|
private static final String LOWER_TAG = "house";
|
||||||
|
|
||||||
@@ -2159,4 +2162,55 @@ public class TaggingServiceImplTest extends TestCase
|
|||||||
assertEquals(tags.get(1).getCount(), 20);
|
assertEquals(tags.get(1).getCount(), 20);
|
||||||
assertEquals(tags.get(2).getCount(), 1);
|
assertEquals(tags.get(2).getCount(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Test adding tags containing \n and | chars. Test all ways to create tag (e.g. createTag, addTag, setTags) */
|
||||||
|
public void testBadTags()
|
||||||
|
{
|
||||||
|
testTag(BAD_TAG);
|
||||||
|
testTag(BAD_TAG2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testTag(final String tag)
|
||||||
|
{
|
||||||
|
this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>(){
|
||||||
|
@Override
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
taggingService.createTag(storeRef, tag);
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(IllegalArgumentException iae)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
taggingService.addTag(document, tag);
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(IllegalArgumentException iae)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<String> setTags = new ArrayList<String>(2);
|
||||||
|
setTags.add(tag);
|
||||||
|
taggingService.setTags(document, setTags);
|
||||||
|
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(IllegalArgumentException iae)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user