Skip to content

Commit 078b461

Browse files
committed
Fix function "uri_encode" to be backwards compatible (metafacture-fix#273)
- introduce options "safe_chars" and "plus_for_space" for function "uri_encode" - update README - bump metafacture dependency to 5.7.0-rc2
1 parent 49e3fb1 commit 078b461

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,20 @@ upcase("<sourceField>")
715715

716716
Encodes a field value as URI. Aka percent-encoding.
717717

718+
Options:
719+
720+
- `allow_empty_values`: Sets whether to allow empty values in the filemap or to ignore these entries. (Default: `false`)
721+
- `compression`: Sets the compression of the file.
722+
723+
724+
```perl
725+
uri_encode("<sourceField>"[, <options>...])
726+
```
727+
728+
E.g.:
729+
718730
```perl
719-
uri_encode("<sourceField>")
731+
uri_encode("path.to.field", plus_for_space:"false", safe_chars:"")
720732
```
721733

722734
### Selectors

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ subprojects {
4444
'jquery': '3.3.1-1',
4545
'junit_jupiter': '5.8.2',
4646
'junit_platform': '1.4.2',
47-
'metafacture': '5.7.0-rc1',
47+
'metafacture': '5.7.0-rc2',
4848
'mockito': '2.27.0',
4949
'requirejs': '2.3.6',
5050
'slf4j': '1.7.21',

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ public void apply(final Metafix metafix, final Record record, final List<String>
668668
@Override
669669
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
670670
final URLEncode urlEncoder = new URLEncode();
671-
urlEncoder.setPlusForSpace(false);
671+
withOption(options, "safe_chars", urlEncoder::setSafeChars);
672+
withOption(options, "plus_for_space", urlEncoder::setPlusForSpace, this::getBoolean);
672673

673674
record.transform(params.get(0), urlEncoder::process);
674675
}

metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,12 +4015,48 @@ public void shouldUriEncodePathSegment() {
40154015
),
40164016
i -> {
40174017
i.startRecord("1");
4018-
i.literal("id", "slash/990223521400206441:DE-A96:61 TYD 16(3)#!");
4018+
i.literal("id", "/DE-A96:% (3)#!");
40194019
i.endRecord();
40204020
},
40214021
o -> {
40224022
o.get().startRecord("1");
4023-
o.get().literal("id", "slash%2F990223521400206441%3ADE%2DA96%3A61%20TYD%2016%283%29%23%21");
4023+
o.get().literal("id", "%2FDE-A96%3A%25+%283%29%23%21");
4024+
o.get().endRecord();
4025+
}
4026+
);
4027+
}
4028+
4029+
@Test
4030+
public void shouldUriEncodePathSegmentWithoutPlusForSpace() {
4031+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
4032+
"uri_encode('id', plus_for_space:'false')"
4033+
),
4034+
i -> {
4035+
i.startRecord("1");
4036+
i.literal("id", "/DE-A96:% (3)#!");
4037+
i.endRecord();
4038+
},
4039+
o -> {
4040+
o.get().startRecord("1");
4041+
o.get().literal("id", "%2FDE-A96%3A%25%20%283%29%23%21");
4042+
o.get().endRecord();
4043+
}
4044+
);
4045+
}
4046+
4047+
@Test
4048+
public void shouldUriEncodePathSegmentWithoutSafeChars() {
4049+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
4050+
"uri_encode('id', safe_chars:'', plus_for_space:'false')"
4051+
),
4052+
i -> {
4053+
i.startRecord("1");
4054+
i.literal("id", "/DE-A96:% (3)#!");
4055+
i.endRecord();
4056+
},
4057+
o -> {
4058+
o.get().startRecord("1");
4059+
o.get().literal("id", "%2FDE%2DA96%3A%25%20%283%29%23%21");
40244060
o.get().endRecord();
40254061
}
40264062
);

0 commit comments

Comments
 (0)