Skip to content

Commit 16be1c0

Browse files
author
mgeipel
committed
fixed #128
1 parent 57709a1 commit 16be1c0

File tree

2 files changed

+42
-5
lines changed
  • src
    • main/java/org/culturegraph/mf/morph/functions
    • test/java/org/culturegraph/mf/morph/functions

2 files changed

+42
-5
lines changed

src/main/java/org/culturegraph/mf/morph/functions/Regexp.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void receive(final String name, final String value, final NamedValueSourc
5050
while (matcher.find()) {
5151
populateVars();
5252
if (!tempVars.isEmpty()) {
53-
getNamedValueReceiver().receive(name,
54-
StringUtil.format(format, tempVars), source, recordCount, entityCount);
53+
getNamedValueReceiver().receive(name, StringUtil.format(format, tempVars), source, recordCount,
54+
entityCount);
5555
}
5656
}
5757
}
@@ -60,8 +60,9 @@ public void receive(final String name, final String value, final NamedValueSourc
6060
private void populateVars() {
6161
tempVars.clear();
6262
for (int i = 0; i <= matcher.groupCount(); ++i) {
63-
if (!matcher.group(i).isEmpty()) {
64-
tempVars.put(String.valueOf(i), matcher.group(i));
63+
final String group = matcher.group(i);
64+
if (group != null && !group.isEmpty()) {
65+
tempVars.put(String.valueOf(i), group);
6566
}
6667
}
6768
}

src/test/java/org/culturegraph/mf/morph/functions/Regexp.xml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<metamorph-test version="1.0"
33
xmlns="http://www.culturegraph.org/metamorph-test" xmlns:cgxml="http://www.culturegraph.org/cgxml"
44
xmlns:mm="http://www.culturegraph.org/metamorph">
5+
56
<test-case name="Regexp function">
67
<input type="text/x-cg+xml">
78
<cgxml:cgxml version="1.0">
@@ -21,7 +22,7 @@
2122
<mm:regexp match=".*" format="resource:P${0}" />
2223
</mm:data>
2324
<mm:data source="001." name="subject">
24-
<mm:regexp match=".*" format="${1}"/>
25+
<mm:regexp match=".*" format="${1}" />
2526
</mm:data>
2627
<mm:data source="001." name="subject">
2728
<mm:regexp match=".*" />
@@ -41,4 +42,39 @@
4142
</cgxml:cgxml>
4243
</result>
4344
</test-case>
45+
46+
47+
<test-case name="empty match group">
48+
<input type="text/x-cg+xml">
49+
<cgxml:cgxml version="1.0">
50+
<cgxml:records>
51+
<cgxml:record id="1">
52+
53+
<cgxml:literal name="s" value="aaccdd" />
54+
<cgxml:literal name="s" value="ax" />
55+
</cgxml:record>
56+
</cgxml:records>
57+
</cgxml:cgxml>
58+
</input>
59+
<transformation type="text/x-metamorph+xml">
60+
<mm:metamorph version="1">
61+
<mm:rules>
62+
<mm:data source="s">
63+
<mm:regexp match="aa(bb*)?(cc*)(dd*)" format="${1}${2}${3}" />
64+
</mm:data>
65+
66+
</mm:rules>
67+
</mm:metamorph>
68+
</transformation>
69+
<result type="text/x-cg+xml">
70+
<cgxml:cgxml version="1.0">
71+
<cgxml:records>
72+
<cgxml:record id="1">
73+
<cgxml:literal name="s" value="ccdd" />
74+
</cgxml:record>
75+
</cgxml:records>
76+
</cgxml:cgxml>
77+
</result>
78+
</test-case>
79+
4480
</metamorph-test>

0 commit comments

Comments
 (0)