Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit b129d44

Browse files
committed
Merge #337 from remote-tracking branch 'origin/273-fixUrlEncode'
2 parents 49e3fb1 + a55c352 commit b129d44

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

README.md

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

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

718+
Options:
719+
720+
- `plus_for_space`: Sets whether "space" (` `) will be substituted by a "plus" (`+`) or be percent escaped (`%20`). (Default: `true`)
721+
- `safe_chars`: Sets characters that won't be escaped. Safe characters are the ranges 0..9, a..z and A..Z. These are always safe and should not be specified. (Default: `.-*_`)
722+
723+
```perl
724+
uri_encode("<sourceField>"[, <options>...])
725+
```
726+
727+
E.g.:
728+
718729
```perl
719-
uri_encode("<sourceField>")
730+
uri_encode("path.to.field", plus_for_space:"false", safe_chars:"")
720731
```
721732

722733
### 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:'')"
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+%283%29%23%21");
40244060
o.get().endRecord();
40254061
}
40264062
);

0 commit comments

Comments
 (0)