Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding for MiniProfiler init script #5553

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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