[HepData-svn] r1930 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Feb 29 11:50:06 GMT 2016


Author: watt
Date: Mon Feb 29 11:50:06 2016
New Revision: 1930

Log:
YAML formatter: escape single-quote characters in units

Modified:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java	Wed Feb 17 16:38:52 2016	(r1929)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java	Mon Feb 29 11:50:06 2016	(r1930)
@@ -403,7 +403,7 @@
 		    if (!ds.getYAxis(1).getHeader().equals(ds.getYAxis(2).getHeader())) { name = ""; unit = ""; }
 		}
 		s.append(sp+"header: {name: '"+name.replaceAll("'","''")+"'");
-		if(!unit.equals("")){ s.append(", units: '"+unit+"'"); }
+		if(!unit.equals("")){ s.append(", units: '"+unit.replaceAll("'","''")+"'"); }
 		s.append("}\n");
 		List <String> storelist = new ArrayList();
 		for (Property prop : yax.getProperties()) {
@@ -566,7 +566,7 @@
 	    unit=xax.getHeader().substring(xax.getHeader().indexOf(" in ")+4).trim();
 	}
 	s.append(sp+"header: {name: '"+name.replaceAll("'","''")+"'");
-	if(!unit.equals("")){ s.append(", units: '"+unit+"'"); }
+	if(!unit.equals("")){ s.append(", units: '"+unit.replaceAll("'","''")+"'"); }
 	s.append("}\n");
 	return s.toString();
 	
@@ -681,7 +681,7 @@
 	}
 	if (prop.getUnit().toString().equals("") || !prop.getUnit().isDimensionless()) {
 	    stemp.append(", units: '");
-	    stemp.append(prop.getUnit().toString()+"'");
+	    stemp.append(prop.getUnit().toString().replaceAll("'","''")+"'");
 	}
 	stemp.append("}\n");
 	return stemp.toString();
@@ -714,7 +714,7 @@
 	stemp.append(s4+sp+"{name: '"+type.replaceAll("'","''").replaceFirst("\\.","zzzz")+"'");
 	stemp.append(", value: '"+ value.replaceAll("'","''")+"'");
 	if(!unit.equals("")){
-	    stemp.append(", units: '"+ unit+"'");
+	    stemp.append(", units: '"+ unit.replaceAll("'","''")+"'");
 	}
 	stemp.append("}\n");
 	return stemp.toString();


More information about the HepData-svn mailing list