Skip to content

Commit

Permalink
XWIKI-16210: Save of document should only be done when hitting save b…
Browse files Browse the repository at this point in the history
…utton in object editor

  * Fix issue with regex for detecting properties and xobjects in
    EditForm
  • Loading branch information
surli committed May 14, 2020
1 parent 526e990 commit c0778ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public class EditForm extends XWikiForm
* {@code <space>.<pageClass>_<number>_<propertyName>} (e.g.
* {@code XWiki.XWikiRights_0_member}).
*/
private static final Pattern XPROPERTY_REFERENCE_PATTERN = Pattern.compile("^(\\w+\\.\\w+?)_([0-9]+)_(.+)$");
private static final Pattern XPROPERTY_REFERENCE_PATTERN = Pattern.compile("^((?:\\w+\\.)+\\w+?)_([0-9]+)_(.+)$");

/**
* Format for passing xobjects references in URLs. General format:
* {@code <space>.<pageClass>_<number>} (e.g.
* {@code XWiki.XWikiRights_0}).
*/
private static final Pattern XOBJECTS_REFERENCE_PATTERN = Pattern.compile("^(\\w+\\.\\w+?)_([0-9]+)$");
private static final Pattern XOBJECTS_REFERENCE_PATTERN = Pattern.compile("^((?:\\w+\\.)+\\w+?)_([0-9]+)$");

private static final String OBJECTS_CLASS_DELIMITER = "_";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void getUpdateOrCreateMap()
parameterMap.put("XWiki.XWikiRights_0_foo", paramValue1);
parameterMap.put("XWiki.XWikiRights_1_foo", paramValue2);
parameterMap.put("XWiki.XWikiRights_1_bar", paramValue3);
parameterMap.put("EditIT.saveActionValidatesWhenXValidateIsPresent.WebHome_0_prop", paramValue1);
parameterMap.put("foobar_18_buz", paramValue1);
parameterMap.put("foo_48bar_buz", paramValue1);

Expand Down Expand Up @@ -130,6 +131,10 @@ public void getUpdateOrCreateMap()
treeMap.put(0, Collections.singletonMap("Something_18_name", paramValue1));
expectedMap.put("MyClass_18_param.WebHome", treeMap);

treeMap = new TreeMap<>();
treeMap.put(0, Collections.singletonMap("prop", paramValue1));
expectedMap.put("EditIT.saveActionValidatesWhenXValidateIsPresent.WebHome", treeMap);

assertEquals(expectedMap, this.editForm.getUpdateOrCreateMap());
}

Expand All @@ -150,6 +155,7 @@ public void getObjectsToAdd()
"XWiki.XWikiRights_foo",
"",
"MyClass_18_param.WebHome_0_Something_18",
"EditIT.saveActionValidatesWhenXValidateIsPresent.WebHome_0",
"XWiki.MyClass_1",
"XWiki.XWikiRights_23",
"AnotherClass_010",
Expand All @@ -162,6 +168,7 @@ public void getObjectsToAdd()
expectedMap.put("XWiki.XWikiRights", Arrays.asList(42, 2, 23));
expectedMap.put("XWiki.MyClass", Collections.singletonList(1));
expectedMap.put("MyClass_18_param.WebHome_0_Something", Collections.singletonList(18));
expectedMap.put("EditIT.saveActionValidatesWhenXValidateIsPresent.WebHome", Collections.singletonList(0));
assertEquals(expectedMap, this.editForm.getObjectsToAdd());
}

Expand All @@ -182,6 +189,7 @@ public void getObjectsToRemove()
"XWiki.XWikiRights_foo",
"",
"MyClass_18_param.WebHome_0_Something_18",
"EditIT.saveActionValidatesWhenXValidateIsPresent.WebHome_0",
"XWiki.MyClass_1",
"XWiki.XWikiRights_23",
"AnotherClass_010",
Expand All @@ -194,6 +202,7 @@ public void getObjectsToRemove()
expectedMap.put("XWiki.XWikiRights", Arrays.asList(42, 2, 23));
expectedMap.put("XWiki.MyClass", Collections.singletonList(1));
expectedMap.put("MyClass_18_param.WebHome_0_Something", Collections.singletonList(18));
expectedMap.put("EditIT.saveActionValidatesWhenXValidateIsPresent.WebHome", Collections.singletonList(0));
assertEquals(expectedMap, this.editForm.getObjectsToRemove());
}
}

0 comments on commit c0778ec

Please sign in to comment.