-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore saveto attributes with incorrect namespaces
- Loading branch information
Showing
4 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/org/javarosa/xform/parse/BindAttributeProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package org.javarosa.xform.parse; | ||
|
||
import kotlin.Pair; | ||
import org.javarosa.core.model.DataBinding; | ||
|
||
import java.util.Set; | ||
|
||
public interface BindAttributeProcessor { | ||
|
||
Set<String> getUsedAttributes(); | ||
Set<Pair<String, String>> getUsedAttributes(); | ||
|
||
void processBindingAttribute(String name, String value, DataBinding binding); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/org/javarosa/entities/internal/EntityFormParseProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.javarosa.entities.internal; | ||
|
||
import kotlin.Pair; | ||
import org.javarosa.core.model.FormDef; | ||
import org.javarosa.core.util.XFormsElement; | ||
import org.javarosa.xform.parse.XFormParser; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.javarosa.core.util.BindBuilderXFormsElement.bind; | ||
import static org.javarosa.core.util.XFormsElement.body; | ||
import static org.javarosa.core.util.XFormsElement.head; | ||
import static org.javarosa.core.util.XFormsElement.input; | ||
import static org.javarosa.core.util.XFormsElement.mainInstance; | ||
import static org.javarosa.core.util.XFormsElement.model; | ||
import static org.javarosa.core.util.XFormsElement.t; | ||
import static org.javarosa.core.util.XFormsElement.title; | ||
|
||
public class EntityFormParseProcessorTest { | ||
|
||
@Test | ||
public void saveTosWithIncorrectNamespaceAreIgnored() throws IOException { | ||
XFormsElement form = XFormsElement.html( | ||
asList( | ||
new Pair<>("correct", "http://www.opendatakit.org/xforms/entities"), | ||
new Pair<>("incorrect", "blah") | ||
), | ||
head( | ||
title("Create entity form"), | ||
model( | ||
mainInstance( | ||
t("data id=\"create-entity-form\"", | ||
t("name"), | ||
t("orx:meta", | ||
t("correct:entity dataset=\"people\"", | ||
t("correct:create") | ||
) | ||
) | ||
) | ||
), | ||
bind("/data/name").type("string").withAttribute("incorrect", "saveto", "name") | ||
) | ||
), | ||
body( | ||
input("/data/name") | ||
) | ||
); | ||
|
||
EntityFormParseProcessor processor = new EntityFormParseProcessor(); | ||
|
||
XFormParser parser = new XFormParser(new InputStreamReader(new ByteArrayInputStream(form.asXml().getBytes()))); | ||
parser.addBindAttributeProcessor(processor); | ||
parser.addFormDefProcessor(processor); | ||
|
||
FormDef formDef = parser.parse(null); | ||
assertThat(formDef.getExtras().get(EntityFormExtra.class).getSaveTos(), is(empty())); | ||
} | ||
} |