Skip to content

Commit

Permalink
Fix rendering of MiniProfiler init script block (#5553)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-tchad authored May 31, 2024
1 parent 259e981 commit 82c2ec2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 6 additions & 6 deletions api/src/org/labkey/api/miniprofiler/MiniProfiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.miniprofiler;

import jakarta.servlet.ServletContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.cache.Cache;
Expand All @@ -27,12 +28,12 @@
import org.labkey.api.security.permissions.TroubleshooterPermission;
import org.labkey.api.util.JavaScriptFragment;
import org.labkey.api.util.MemTracker;
import org.labkey.api.util.SafeToRender;
import org.labkey.api.util.SafeToRenderEnum;
import org.labkey.api.view.HttpView;
import org.labkey.api.view.ViewContext;
import org.labkey.api.view.ViewServlet;

import jakarta.servlet.ServletContext;
import java.security.Principal;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -151,12 +152,11 @@ public static void resetSettings(@NotNull User user)
SETTINGS_CACHE.remove(user);
}

public static JavaScriptFragment renderInitScript(@NotNull User user, long currentId, Set<Long> ids, String version)
public static SafeToRender renderInitScript(@NotNull User user, long currentId, Set<Long> ids, String version)
{
Settings settings = getSettings(user);

return JavaScriptFragment.unsafe(
HttpView.currentPageConfig().getScriptTagStart().toString() +
JavaScriptFragment initFragment = JavaScriptFragment.unsafe(
"LABKEY.internal.MiniProfiler.init({\n" +
" currentId:" + currentId + ",\n" +
" ids:" + ids + ",\n" +
Expand All @@ -171,9 +171,9 @@ public static JavaScriptFragment renderInitScript(@NotNull User user, long curre
" toggleShortcut:" + jsString(settings.getToggleShortcut() != null ? settings.getToggleShortcut() : "") + ",\n" +
" startHidden:" + settings.isStartHidden() + ",\n" +
" startMinimized:" + settings.isStartMinimized() + "\n" +
"});\n" +
"</script>\n"
"});"
);
return HttpView.currentPageConfig().buildScriptTagBlock(initFragment);
}

public static void addObject(Object object)
Expand Down
18 changes: 16 additions & 2 deletions api/src/org/labkey/api/view/template/PageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.labkey.api.view.template;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -32,6 +34,8 @@
import org.labkey.api.util.HtmlStringBuilder;
import org.labkey.api.util.JavaScriptFragment;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.SafeToRender;
import org.labkey.api.util.SafeToRenderBuilder;
import org.labkey.api.util.URLHelper;
import org.labkey.api.util.UniqueID;
import org.labkey.api.util.logging.LogHelper;
Expand All @@ -43,8 +47,6 @@
import org.labkey.api.view.ViewServlet;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
Expand Down Expand Up @@ -598,6 +600,18 @@ public HtmlString getScriptTagStart()
}


public SafeToRender buildScriptTagBlock(JavaScriptFragment javaScriptFragment)
{
SafeToRenderBuilder scriptBuilder = SafeToRenderBuilder.of();
scriptBuilder.append(HttpView.currentPageConfig().getScriptTagStart());
scriptBuilder.append(HtmlString.unsafe("\n"));
scriptBuilder.append(javaScriptFragment);
scriptBuilder.append(HtmlString.unsafe("\n</script>\n"));
return scriptBuilder.getSafeToRender();
}



private void _addHandler(EventHandler eh)
{
if (_eventHandlers.size() <= MAX_EVENT_HANDLERS)
Expand Down

0 comments on commit 82c2ec2

Please sign in to comment.