Skip to content

Commit 9e2ab1f

Browse files
authored
Issue 52247: DataRegion.renderForm to encode primary key hidden input name property for update row case (#2276)
- Add selenium test case for issue 52247: ListTest.testAutoIncrementKeyEncoded
1 parent e8690f7 commit 9e2ab1f

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

src/org/labkey/test/tests/list/ListTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
package org.labkey.test.tests.list;
1818

19+
import org.apache.commons.lang3.StringUtils;
1920
import org.hamcrest.CoreMatchers;
2021
import org.hamcrest.MatcherAssert;
2122
import org.junit.Before;
2223
import org.junit.BeforeClass;
2324
import org.junit.Ignore;
2425
import org.junit.Test;
2526
import org.junit.experimental.categories.Category;
27+
import org.labkey.api.query.QueryKey;
2628
import org.labkey.remoteapi.CommandException;
2729
import org.labkey.remoteapi.domain.Domain;
2830
import org.labkey.remoteapi.domain.DomainResponse;
@@ -38,6 +40,7 @@
3840
import org.labkey.test.categories.Daily;
3941
import org.labkey.test.categories.Data;
4042
import org.labkey.test.categories.Hosting;
43+
import org.labkey.test.components.CustomizeView;
4144
import org.labkey.test.components.domain.BaseDomainDesigner;
4245
import org.labkey.test.components.domain.ConditionalFormatDialog;
4346
import org.labkey.test.components.domain.DomainFieldRow;
@@ -1384,6 +1387,51 @@ public void testFieldUniqueConstraint()
13841387
assertTextNotPresent("unique_constraint_list_fieldname_2");
13851388
}
13861389

1390+
@Test // Issue 52247
1391+
public void testAutoIncrementKeyEncoded()
1392+
{
1393+
// setup a list with an auto-increment key that we need to make sure is encoded in the form input
1394+
String encodedListName = "autoIncrementEncodeList";
1395+
String keyName = "'><script>alert(\":(\")</script>'";
1396+
String encodedKeyName = StringUtils.replace(keyName, "\"", "&quot;");
1397+
_listHelper.createList(PROJECT_VERIFY, encodedListName, keyName, col("Name", ColumnType.String));
1398+
_listHelper.goToList(encodedListName);
1399+
1400+
DataRegionTable table = new DataRegionTable("query", getDriver());
1401+
CustomizeView customizeView = table.openCustomizeGrid();
1402+
customizeView.showHiddenItems();
1403+
customizeView.addColumn(QueryKey.encodePart(keyName));
1404+
customizeView.applyCustomView();
1405+
1406+
// insert a new row and verify the key is encoded in the form input
1407+
table.clickInsertNewRow();
1408+
String html = getHtmlSource();
1409+
checker().verifyFalse("List key hidden input not present.", html.contains("quf_" + encodedKeyName));
1410+
String nameValue = "test";
1411+
setFormElement(Locator.name("quf_Name"), nameValue);
1412+
clickButton("Submit");
1413+
1414+
// verify the name value is persisted
1415+
table = new DataRegionTable("query", getDriver());
1416+
checker().verifyEquals("Key value not as expected", "1", table.getDataAsText(0, keyName));
1417+
checker().verifyEquals("Name value not as expected", nameValue, table.getDataAsText(0, "Name"));
1418+
1419+
// verify name value can be updated
1420+
table.clickEditRow(0);
1421+
html = getHtmlSource();
1422+
checker().verifyTrue("List key hidden input not present.", html.contains("quf_" + encodedKeyName));
1423+
nameValue = "test updated";
1424+
setFormElement(Locator.name("quf_Name"), nameValue);
1425+
clickButton("Submit");
1426+
1427+
// verify the name value is persisted
1428+
table = new DataRegionTable("query", getDriver());
1429+
checker().verifyEquals("Key value not as expected", "1", table.getDataAsText(0, keyName));
1430+
checker().verifyEquals("Name value not as expected", nameValue, table.getDataAsText(0, "Name"));
1431+
1432+
_listHelper.deleteList();
1433+
}
1434+
13871435
private void viewRawTableMetadata(String listName)
13881436
{
13891437
goToSchemaBrowser();

0 commit comments

Comments
 (0)