Skip to content
Merged
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
18 changes: 16 additions & 2 deletions src/org/labkey/test/util/EscapeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.labkey.test.util;

import org.apache.commons.text.StringEscapeUtils;
import org.apache.poi.ss.util.WorkbookUtil;
import org.eclipse.jetty.util.URIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -212,9 +213,22 @@ public static String getMarkupEscapedValue(String value)
}

private static final Pattern nameExpressionNeedsEscaping = Pattern.compile("([\\\\$/&}~,.])");
public static String escapeForNameExpression(String name)
public static String escapeForNameExpression(String value)
{
return nameExpressionNeedsEscaping.matcher(name).replaceAll("\\\\$1");
return nameExpressionNeedsEscaping.matcher(value).replaceAll("\\\\$1");
}

private static final Pattern excelPageNeedsEscaping = Pattern.compile("([:/])");
/**
* Escapes invalid characters in a string to ensure it can be used as a valid Excel sheet name.
* Replaces characters matching the {@code excelPageNeedsEscaping} pattern with an underscore ("_").
*
* @param value the input string to be escaped
* @return the escaped string that can safely be used as an Excel sheet name
*/
public static String escapeForExcelSheetName(String value)
{
return WorkbookUtil.createSafeSheetName(value, '_');
}
Comment on lines 229 to 232
Copy link
Member

@labkey-tchad labkey-tchad Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an existing, more thorough method for this (it's what is used on the server side). org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(java.lang.String, char)

Suggested change
public static String escapeForExcelSheetName(String value)
{
return excelPageNeedsEscaping.matcher(value).replaceAll("_");
}
public static String createSafeSheetName(String value)
{
return WorkbookUtil.createSafeSheetName(value, '_');
}

Also, this isn't escaping (escaping is reversible). Consider moving this method to ExcelHelper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.


/**
Expand Down