Skip to content

Commit 2207ca8

Browse files
authored
Don't turn Jupyter JSON outputs into HTML (#6835)
1 parent 00b5c76 commit 2207ca8

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

api/src/org/labkey/api/reports/report/r/view/HtmlOutput.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public HtmlOutputView(ParamReplacement param, String label)
9090
setLabel(label);
9191
}
9292

93+
/**
94+
* Loads an HTML file and adds nonces to any embedded <script> tags. Don't call this with files that aren't HTML.
95+
*/
9396
@Override
9497
protected String renderInternalAsString(File file) throws Exception
9598
{

api/src/org/labkey/api/reports/report/r/view/IpynbOutput.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.labkey.api.util.HtmlString;
3232
import org.labkey.api.util.HtmlStringBuilder;
3333
import org.labkey.api.util.ImageUtil;
34+
import org.labkey.api.util.PageFlowUtil;
3435
import org.labkey.api.view.HttpView;
3536
import org.labkey.api.view.ViewContext;
3637

@@ -92,7 +93,7 @@ public HttpView<?> getView(ViewContext context)
9293
{
9394
String html = view.renderInternalAsString(file);
9495
URI baseURI = new URI(AppProps.getInstance().getBaseServerUrl());
95-
if (html != null && baseURI != null)
96+
if (html != null)
9697
thumb = ImageUtil.webThumbnail(context, html, baseURI);
9798
}
9899
catch(Exception ignore){}// if we can't get a thumbnail then that is okay; LabKey should use a default
@@ -149,7 +150,8 @@ String stripAnsiColors(String s)
149150
@Override
150151
protected String renderInternalAsString(File file) throws Exception
151152
{
152-
String result = StringUtils.trimToEmpty(super.renderInternalAsString(file));
153+
// Don't call super.renderInternalAsString(file) since we expect JSON
154+
String result = file.exists() ? StringUtils.trimToEmpty(PageFlowUtil.getFileContentsAsString(file)) : "";
153155
try
154156
{
155157
final JSONObject obj = new JSONObject(result);

api/src/org/labkey/api/util/PageFlowUtil.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,14 +3166,21 @@ public static String addScriptNonces(String html)
31663166
String ret = "";
31673167
if (doc != null)
31683168
{
3169-
addScriptNonces(doc);
3170-
try
3169+
if (addScriptNonces(doc) > 0)
31713170
{
3172-
ret = convertNodeToHtml(doc);
3171+
try
3172+
{
3173+
ret = convertNodeToHtml(doc);
3174+
}
3175+
catch (TransformerException | IOException e)
3176+
{
3177+
throw new RuntimeException(e);
3178+
}
31733179
}
3174-
catch (TransformerException | IOException e)
3180+
else
31753181
{
3176-
throw new RuntimeException(e);
3182+
// If there are no script tags, just return the passed in HTML
3183+
ret = html;
31773184
}
31783185
}
31793186

0 commit comments

Comments
 (0)