Anonymous avatar Anonymous committed fbf7733 Merge

Bringing in changes from production

Comments (0)

Files changed (1)

ingest-src/src/main/java/org/cdlib/mrt/ingest/utility/MintUtil.java

     		String collection = (String) collections.next();
 		if (collection.startsWith("ark:/")) {
 		    System.out.println("[info] " + MESSAGE + "Found group identifier: " + collection);
-		    group = "&group=" + collection;
+		    group = "&group=" + escape(collection);
 		    break;
 		} else {
 		    System.err.println("[warning] " + MESSAGE + "Collection ID is not a valid group identifier: " + collection);
 	    try {
 		// e.g. http://merritt.cdlib.org/object?object=ark%3A%2F99999%2Ffk40v8k3k&group=ark:/13030/fk4...
 		target = "_target: " + "http://merritt.cdlib.org/object?object=" + 
-			URLEncoder.encode(jobState.getPrimaryID().getValue(), "UTF-8") + group;
+			URLEncoder.encode(jobState.getPrimaryID().getValue(), "UTF-8") + escape(group);
 	    } catch (Exception e) { }
 
 	    // Is context available?
 	    String context = "";
 	    try {
-	        context = "mrt.creator: " + profileState.getContext();
+	        context = "mrt.creator: " + escape(profileState.getContext());
 	    } catch (Exception e) { }
 
 	    httpCommand = new HttpPost(url);
         try {
 	    String md = "";
 	    try {
-		md += "who: " + jobState.getObjectCreator() + EOL;
+		md += "who: " + escape(jobState.getObjectCreator()) + EOL;
 	    } catch (Exception e) {}
 	    try {
-		md += "what: " + jobState.getObjectTitle() + EOL;
+		md += "what: " + escape(jobState.getObjectTitle()) + EOL;
 	    } catch (Exception e) {}
 	    try {
-		md += "when: " + jobState.getObjectDate() + EOL;
+		md += "when: " + escape(jobState.getObjectDate()) + EOL;
 	    } catch (Exception e) {}
 	    try {
-		md += "where: " + jobState.getPrimaryID().getValue() + EOL;
+		md += "where: " + escape(jobState.getPrimaryID().getValue()) + EOL;
 	    } catch (Exception e) {}
 	    try {
-		md += "where: " + jobState.getLocalID().getValue() + EOL;
+		md += "where: " + escape(jobState.getLocalID().getValue()) + EOL;
 	    } catch (Exception e) {}
 
             return md;
         } catch (Exception ex) {
-            throw new TException.GENERAL_EXCEPTION("error accessing metadata");
+            throw new TException.GENERAL_EXCEPTION("error processing metadata");
         }
     }
 
+    private static String escape(String input)
+        throws TException
+    {
+        try {
+		return input.replaceAll("%", "%25").replaceAll("\n", "%0A").replaceAll("\r", "%0D").replaceAll(":", "%3A");
+        } catch (Exception ex) {
+            throw new TException.GENERAL_EXCEPTION("escaping ERC metadata");
+        }
+    }
+
+
+
     private static String getTargetURL(JobState jobState)
         throws TException
     {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.