Follow up to 'Add enabledExperiments to soy template'
Issue:
At present state adding experimental flags results in the following
line being added to the '<script>' section of header:
window.ENABLED_EXPERIMENTS = JSON.parse(["flag"])
and JSON.parse fails with the following error:
Uncaught SyntaxError: Unexpected token l in JSON at position 1
at JSON.parse (<anonymous>)
at <anonymous>:1:6
Solution:
Turn the sanitized object toString() so that it results in JSON-parsable
string:
window.ENABLED_EXPERIMENTS = JSON.parse('\x5b\x22flag\x22\x5d')
Change-Id: Ida7e8faa6679880a2204489fbf604fee27ae2cd0
diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
index cddaea4..1680457 100644
--- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
+++ b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
@@ -125,7 +125,7 @@
Set<String> enabledExperiments = experimentData(urlParameterMap);
if (!enabledExperiments.isEmpty()) {
- data.put("enabledExperiments", serializeObject(GSON, enabledExperiments));
+ data.put("enabledExperiments", serializeObject(GSON, enabledExperiments).toString());
}
return data.build();
}