From 63b9af892581e27dd7dc12ad5bab7b35171fd92a Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 31 Jan 2015 11:37:48 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud) 91710: Merged 5.0.N (5.0.1) to HEAD-BUG-FIX (5.1/Cloud) 91606: Merged V4.2-BUG-FIX (4.2.5) to 5.0.N (5.0.1) << Merging only new CMIS >> 91469: Merged V4.2.4 (4.2.4) to V4.2-BUG-FIX (4.2.5) 91306: Merged DEV to PATCHES/4.2.4 91267 : MNT-12496: CMIS: Unable to navigate to a folder if it has image with special character on the metadata - Escaping of control characters was added 91286 : MNT-12496: CMIS: Unable to navigate to a folder if it has image with special character on the metadata - Added tests to check incorrect char in description property of node. 91470: Merged V4.2.4 (4.2.4) to V4.2-BUG-FIX (4.2.5) 91313: MNT-12496: CMIS: Unable to navigate to a folder if it has image with special character on the metadata - Build failure fixed git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94826 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/opencmis/CMISConnector.java | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/source/java/org/alfresco/opencmis/CMISConnector.java b/source/java/org/alfresco/opencmis/CMISConnector.java index 433dfe42ec..e76d49eb2c 100644 --- a/source/java/org/alfresco/opencmis/CMISConnector.java +++ b/source/java/org/alfresco/opencmis/CMISConnector.java @@ -2118,7 +2118,16 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen return df.newXMLGregorianCalendar((GregorianCalendar) value).toXMLFormat(); } - return value.toString(); + // MNT-12496 + // Encode for AtomPub only. Browser/json binding already encodes. + if (AlfrescoCmisServiceCall.get() != null && CallContext.BINDING_ATOMPUB.equals(AlfrescoCmisServiceCall.get().getBinding())) + { + return escapeControlCharacters(value.toString()); + } + else + { + return value.toString(); + } } @SuppressWarnings("unchecked") @@ -2213,7 +2222,16 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen } else { - ((PropertyStringImpl) result).setValue((String) value); + // MNT-12496 + // Encode for AtomPub only. Browser/json binding already encodes. + if (AlfrescoCmisServiceCall.get() != null && CallContext.BINDING_ATOMPUB.equals(AlfrescoCmisServiceCall.get().getBinding())) + { + ((PropertyStringImpl) result).setValue(escapeControlCharacters((String) value)); + } + else + { + ((PropertyStringImpl) result).setValue((String) value); + } } break; case URI: @@ -2241,6 +2259,47 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen return result; } + + private String escapeControlCharacters(String origValue) + { + if (origValue == null) + { + return origValue; + } + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < origValue.length(); i++) + { + char ch = origValue.charAt(i); + switch (ch) + { + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + sb.append(ch); + break; + default: + // Reference: http://www.unicode.org/versions/Unicode5.1.0/ + if ((ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u007F' && ch <= '\u009F') || (ch >= '\u2000' && ch <= '\u20FF')) + { + String ss = Integer.toHexString(ch); + sb.append("\\u"); + for (int k = 0; k < 4 - ss.length(); k++) + { + sb.append('0'); + } + sb.append(ss.toUpperCase()); + } + else + { + sb.append(ch); + } + } + } + return sb.toString(); + } private Set splitFilter(String filter) {