|
16 | 16 |
|
17 | 17 | package org.labkey.test.tests.list; |
18 | 18 |
|
| 19 | +import org.apache.commons.lang3.StringUtils; |
19 | 20 | import org.hamcrest.CoreMatchers; |
20 | 21 | import org.hamcrest.MatcherAssert; |
21 | 22 | import org.junit.Before; |
22 | 23 | import org.junit.BeforeClass; |
23 | 24 | import org.junit.Ignore; |
24 | 25 | import org.junit.Test; |
25 | 26 | import org.junit.experimental.categories.Category; |
| 27 | +import org.labkey.api.query.QueryKey; |
26 | 28 | import org.labkey.remoteapi.CommandException; |
27 | 29 | import org.labkey.remoteapi.domain.Domain; |
28 | 30 | import org.labkey.remoteapi.domain.DomainResponse; |
|
38 | 40 | import org.labkey.test.categories.Daily; |
39 | 41 | import org.labkey.test.categories.Data; |
40 | 42 | import org.labkey.test.categories.Hosting; |
| 43 | +import org.labkey.test.components.CustomizeView; |
41 | 44 | import org.labkey.test.components.domain.BaseDomainDesigner; |
42 | 45 | import org.labkey.test.components.domain.ConditionalFormatDialog; |
43 | 46 | import org.labkey.test.components.domain.DomainFieldRow; |
@@ -1384,6 +1387,51 @@ public void testFieldUniqueConstraint() |
1384 | 1387 | assertTextNotPresent("unique_constraint_list_fieldname_2"); |
1385 | 1388 | } |
1386 | 1389 |
|
| 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, "\"", """); |
| 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 | + |
1387 | 1435 | private void viewRawTableMetadata(String listName) |
1388 | 1436 | { |
1389 | 1437 | goToSchemaBrowser(); |
|
0 commit comments