diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index b53d9dc..a4035eb 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -13,7 +13,7 @@ plugins { id("com.github.ben-manes.versions") version "0.46.0" } -val rifeVersion by rootProject.extra { "1.5.6" } +val rifeVersion by rootProject.extra { "1.5.5" } group = "com.uwyn.rife2" version = "1.0.1-SNAPSHOT" diff --git a/lib/src/main/java/rife/render/Abbreviate.java b/lib/src/main/java/rife/render/Abbreviate.java index 6944aa4..cfe679a 100644 --- a/lib/src/main/java/rife/render/Abbreviate.java +++ b/lib/src/main/java/rife/render/Abbreviate.java @@ -57,8 +57,6 @@ public class Abbreviate implements ValueRenderer { // do nothing } } - - return template.getEncoder().encode( - RenderUtils.abbreviate(template.getValueOrAttribute(differentiator), max, mark)); + return RenderUtils.abbreviate(template.getValueOrAttribute(differentiator), max, mark); } -} \ No newline at end of file +} diff --git a/lib/src/main/java/rife/render/BeatTime.java b/lib/src/main/java/rife/render/BeatTime.java index dd4cfad..e1eaf44 100644 --- a/lib/src/main/java/rife/render/BeatTime.java +++ b/lib/src/main/java/rife/render/BeatTime.java @@ -42,6 +42,6 @@ public class BeatTime implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(RenderUtils.beatTime(ZonedDateTime.now())); + return RenderUtils.beatTime(ZonedDateTime.now()); } } \ No newline at end of file diff --git a/lib/src/main/java/rife/render/Capitalize.java b/lib/src/main/java/rife/render/Capitalize.java index dc4c126..9e9bd91 100644 --- a/lib/src/main/java/rife/render/Capitalize.java +++ b/lib/src/main/java/rife/render/Capitalize.java @@ -19,7 +19,6 @@ package rife.render; import rife.template.Template; import rife.template.ValueRenderer; -import rife.tools.StringUtils; /** *

Capitalizes a template value.

@@ -41,6 +40,6 @@ public class Capitalize implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(StringUtils.capitalize(template.getValueOrAttribute(differentiator))); + return RenderUtils.capitalize(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/DateIso.java b/lib/src/main/java/rife/render/DateIso.java index 3fe35c6..b261268 100644 --- a/lib/src/main/java/rife/render/DateIso.java +++ b/lib/src/main/java/rife/render/DateIso.java @@ -42,6 +42,6 @@ public class DateIso implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(ZonedDateTime.now().format(RenderUtils.ISO_8601_DATE_FORMATTER)); + return ZonedDateTime.now().format(RenderUtils.ISO_8601_DATE_FORMATTER); } } diff --git a/lib/src/main/java/rife/render/DateTimeIso.java b/lib/src/main/java/rife/render/DateTimeIso.java index 50ac866..683abb7 100644 --- a/lib/src/main/java/rife/render/DateTimeIso.java +++ b/lib/src/main/java/rife/render/DateTimeIso.java @@ -61,6 +61,6 @@ public class DateTimeIso implements ValueRenderer { } } - return template.getEncoder().encode(ZonedDateTime.now().format(RenderUtils.ISO_8601_FORMATTER)); + return ZonedDateTime.now().format(RenderUtils.ISO_8601_FORMATTER); } } diff --git a/lib/src/main/java/rife/render/DateTimeRfc2822.java b/lib/src/main/java/rife/render/DateTimeRfc2822.java index a420201..5058b70 100644 --- a/lib/src/main/java/rife/render/DateTimeRfc2822.java +++ b/lib/src/main/java/rife/render/DateTimeRfc2822.java @@ -42,6 +42,6 @@ public class DateTimeRfc2822 implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(ZonedDateTime.now().format(RenderUtils.RFC_2822_FORMATTER)); + return ZonedDateTime.now().format(RenderUtils.RFC_2822_FORMATTER); } } diff --git a/lib/src/main/java/rife/render/EncodeBase64.java b/lib/src/main/java/rife/render/EncodeBase64.java index fd2e62a..c5bd854 100644 --- a/lib/src/main/java/rife/render/EncodeBase64.java +++ b/lib/src/main/java/rife/render/EncodeBase64.java @@ -44,9 +44,7 @@ public class EncodeBase64 implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - var properties = RenderUtils.parsePropertiesString(template.getDefaultValue(valueId)); - return RenderUtils.encode( - StringUtils.encodeBase64(template.getValueOrAttribute(differentiator).getBytes(StandardCharsets.UTF_8)), - properties); + return StringUtils.encodeBase64(template.getValueOrAttribute(differentiator) + .getBytes(StandardCharsets.UTF_8)); } } diff --git a/lib/src/main/java/rife/render/EncodeJs.java b/lib/src/main/java/rife/render/EncodeJs.java index 1122356..caafb18 100644 --- a/lib/src/main/java/rife/render/EncodeJs.java +++ b/lib/src/main/java/rife/render/EncodeJs.java @@ -42,7 +42,6 @@ public class EncodeJs implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - var properties = RenderUtils.parsePropertiesString(template.getDefaultValue(valueId)); - return RenderUtils.encode(RenderUtils.encodeJs(template.getValueOrAttribute(differentiator)), properties); + return RenderUtils.encodeJs(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/EncodeJson.java b/lib/src/main/java/rife/render/EncodeJson.java index 7356650..60916f6 100644 --- a/lib/src/main/java/rife/render/EncodeJson.java +++ b/lib/src/main/java/rife/render/EncodeJson.java @@ -42,7 +42,6 @@ public class EncodeJson implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - var properties = RenderUtils.parsePropertiesString(template.getDefaultValue(valueId)); - return RenderUtils.encode(StringUtils.encodeJson(template.getValueOrAttribute(differentiator)), properties); + return StringUtils.encodeJson(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/EncodeUnicode.java b/lib/src/main/java/rife/render/EncodeUnicode.java index 60166a1..1d67bf1 100644 --- a/lib/src/main/java/rife/render/EncodeUnicode.java +++ b/lib/src/main/java/rife/render/EncodeUnicode.java @@ -42,7 +42,6 @@ public class EncodeUnicode implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - var properties = RenderUtils.parsePropertiesString(template.getDefaultValue(valueId)); - return RenderUtils.encode(StringUtils.encodeUnicode(template.getValueOrAttribute(differentiator)), properties); + return StringUtils.encodeUnicode(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/EncodeUrl.java b/lib/src/main/java/rife/render/EncodeUrl.java index 6692636..f6201d5 100644 --- a/lib/src/main/java/rife/render/EncodeUrl.java +++ b/lib/src/main/java/rife/render/EncodeUrl.java @@ -42,7 +42,6 @@ public class EncodeUrl implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - var properties = RenderUtils.parsePropertiesString(template.getDefaultValue(valueId)); - return RenderUtils.encode(StringUtils.encodeUrl(template.getValueOrAttribute(differentiator)), properties); + return StringUtils.encodeUrl(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/FormatCreditCard.java b/lib/src/main/java/rife/render/FormatCreditCard.java index f2025eb..840d66e 100644 --- a/lib/src/main/java/rife/render/FormatCreditCard.java +++ b/lib/src/main/java/rife/render/FormatCreditCard.java @@ -40,6 +40,6 @@ public class FormatCreditCard implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(RenderUtils.formatCreditCard(template.getValueOrAttribute(differentiator))); + return RenderUtils.formatCreditCard(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/Lowercase.java b/lib/src/main/java/rife/render/Lowercase.java index aa7858c..d966142 100644 --- a/lib/src/main/java/rife/render/Lowercase.java +++ b/lib/src/main/java/rife/render/Lowercase.java @@ -45,6 +45,6 @@ public class Lowercase implements ValueRenderer { if (value == null || value.isBlank()) { return value; } - return template.getEncoder().encode(value.toLowerCase(Localization.getLocale())); + return value.toLowerCase(Localization.getLocale()); } } diff --git a/lib/src/main/java/rife/render/Mask.java b/lib/src/main/java/rife/render/Mask.java index a9c1e22..897b415 100644 --- a/lib/src/main/java/rife/render/Mask.java +++ b/lib/src/main/java/rife/render/Mask.java @@ -59,7 +59,6 @@ public class Mask implements ValueRenderer { // do nothing } } - return template.getEncoder().encode( - RenderUtils.mask(template.getValueOrAttribute(differentiator), mask, unmasked, fromStart)); + return RenderUtils.mask(template.getValueOrAttribute(differentiator), mask, unmasked, fromStart); } } diff --git a/lib/src/main/java/rife/render/Normalize.java b/lib/src/main/java/rife/render/Normalize.java index c3e66a2..636c8cb 100644 --- a/lib/src/main/java/rife/render/Normalize.java +++ b/lib/src/main/java/rife/render/Normalize.java @@ -40,6 +40,6 @@ public class Normalize implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(RenderUtils.normalize(template.getValueOrAttribute(differentiator))); + return RenderUtils.normalize(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/RenderUtils.java b/lib/src/main/java/rife/render/RenderUtils.java index 139d17f..e9fbe3c 100644 --- a/lib/src/main/java/rife/render/RenderUtils.java +++ b/lib/src/main/java/rife/render/RenderUtils.java @@ -21,7 +21,6 @@ import rife.tools.Localization; import rife.tools.StringUtils; import java.io.IOException; -import java.io.StringReader; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -40,11 +39,6 @@ import java.util.concurrent.TimeUnit; * @since 1.0 */ public final class RenderUtils { - /** - * The encoding property. - */ - public static final String ENCODING_PROPERTY = "encoding"; - /** * ISO 8601 date formatter. * @@ -88,12 +82,12 @@ public final class RenderUtils { } /** - * Abbreviates a {@code String} to the given length using a replacement marker. + * Abbreviates a String to the given length using a replacement marker. * - * @param src the source {@code String} - * @param max the maximum length of the resulting {@code String} - * @param marker the {@code String} used as a replacement marker - * @return the abbreviated {@code String} + * @param src the source String + * @param max the maximum length of the resulting String + * @param marker the String used as a replacement marker + * @return the abbreviated String */ public static String abbreviate(String src, int max, String marker) { if (src == null || src.isBlank() || marker == null) { @@ -112,7 +106,7 @@ public final class RenderUtils { /** * Returns the Swatch Internet (.beat) Time for the give date-time. * - * @param zonedDateTime the date and time + * @param zonedDateTime the date and time. * @return the .beat time. (eg.: {@code @248}) */ public static String beatTime(ZonedDateTime zonedDateTime) { @@ -123,59 +117,23 @@ public final class RenderUtils { } /** - *

Encodes the source {@code String} to the specified encoding.

+ * Capitalizes a String. * - *

The supported encodings are:

- * - * - * - * @param src the source {@code String} to encode - * @param properties the properties containing the {@link #ENCODING_PROPERTY encoding property}. - * @return the encoded {@code String} + * @param src the source String + * @return the capitalized String */ - public static String encode(String src, Properties properties) { - if (src == null || src.isBlank() || properties.isEmpty()) { + public static String capitalize(String src) { + if (src == null || src.isBlank()) { return src; } - - var encoding = properties.getProperty(ENCODING_PROPERTY, ""); - switch (encoding) { - case "html" -> { - return StringUtils.encodeHtml(src); - } - case "js" -> { - return RenderUtils.encodeJs(src); - } - case "json" -> { - return StringUtils.encodeJson(src); - } - case "unicode" -> { - return StringUtils.encodeUnicode(src); - } - case "url" -> { - return StringUtils.encodeUrl(src); - } - case "xml" -> { - return StringUtils.encodeXml(src); - } - default -> { - return src; - } - } + return src.substring(0, 1).toUpperCase(Localization.getLocale()) + src.substring(1); } /** - * Encodes a {@code String} to JavaScript/ECMAScript. + * Encodes a String to JavaScript/ECMAScript. * - * @param src the source {@code String} - * @return the encoded {@code String} + * @param src the source String + * @return the encoded String */ public static String encodeJs(String src) { if (src == null || src.isBlank()) { @@ -202,9 +160,9 @@ public final class RenderUtils { /** * Fetches the content (body) of a URL. * - * @param url the URL {@code String} - * @param defaultContent the default content to return if none fetched - * @return the url content, or empty + * @param url the URL sSng. + * @param defaultContent the default content to return if none fetched. + * @return the url content, or empty. */ public static String fetchUrl(String url, String defaultContent) { try { @@ -223,12 +181,8 @@ public final class RenderUtils { } /** - *

Returns the last 4 digits a credit card number.

- * - * + * Returns the last 4 digits a credit card number. The number must satisfy the Luhn algorithm. + * Non-digits are stripped from the number. * * @param src the credit card number * @return the last 4 digits of the credit card number or empty @@ -248,10 +202,10 @@ public final class RenderUtils { } /** - * Converts a text {@code String} to HTML decimal entities. + * Converts a text String to HTML decimal entities. * - * @param src the {@code String} to convert - * @return the converted {@code String} + * @param src the String to convert + * @return the converted String */ @SuppressWarnings("PMD.AvoidReassigningLoopVariables") public static String htmlEntities(String src) { @@ -278,11 +232,11 @@ public final class RenderUtils { /** * Masks characters in a String. * - * @param src the source {@code String} - * @param mask the {@code String} to mask characters with + * @param src the source String. + * @param mask the String to mask characters with * @param unmasked the number of characters to leave unmasked - * @param fromStart to unmask characters from the start of the {@code String} - * @return the masked {@code String} + * @param fromStart to unmask characters from the start of the String + * @return the masked String */ public static String mask(String src, String mask, int unmasked, boolean fromStart) { if (src == null || src.isEmpty()) { @@ -306,10 +260,10 @@ public final class RenderUtils { } /** - * Normalizes a {@code String} for inclusion in a URL path. + * Normalizes a String for inclusion in a URL path. * - * @param src the source {@code String} - * @return the normalized {@code String} + * @param src The source String + * @return the normalized String */ public static String normalize(String src) { if (src == null || src.isBlank()) { @@ -337,31 +291,13 @@ public final class RenderUtils { return sb.toString(); } - /** - * Returns a new {@code Properties} containing the properties specified in the given {$String}. - * - * @param src the {@code} String containing the properties - * @return the new {@code Properties} - */ - public static Properties parsePropertiesString(String src) { - var properties = new Properties(); - if (src != null && !src.isBlank()) { - try { - properties.load(new StringReader(src)); - } catch (IOException ignore) { - // ignore - } - } - return properties; - } - /** * Returns the plural form of a word, if count > 1. * * @param count the count * @param word the singular word * @param plural the plural word - * @return the singular or plural {@code String} + * @return the singular or plural String */ public static String plural(final long count, final String word, final String plural) { if (count > 1) { @@ -372,9 +308,9 @@ public final class RenderUtils { } /** - * Generates an SVG QR Code from the given {@code String} using goQR.me. + * Generates an SVG QR Code from the given String using goQR.me. * - * @param src the data {@code String} + * @param src the data String * @param size the QR Code size. (e.g. {@code 150x150}) * @return the QR code */ @@ -389,10 +325,10 @@ public final class RenderUtils { } /** - * Translates a {@code String} to/from ROT13. + * Translates a String to/from ROT13. * - * @param src the source {@code String} - * @return the translated {@code String} + * @param src the source String + * @return the translated String */ public static String rot13(String src) { if (src == null || src.isBlank()) { @@ -430,7 +366,7 @@ public final class RenderUtils { /** *

Shortens a URL using is.gid.

* - *

The URL {@code String} must be a valid http or https URL.

+ *

The URL String must be a valid http or https URL.

* *

Based on isgd-shorten

* @@ -448,8 +384,8 @@ public final class RenderUtils { /** * Swaps the case of a String. * - * @param src the {@code String} to swap the case of - * @return the modified {@code String} or null + * @param src the String to swap the case of + * @return the modified String or null */ @SuppressWarnings("PMD.AvoidReassigningLoopVariables") public static String swapCase(String src) { @@ -477,6 +413,19 @@ public final class RenderUtils { return new String(buff, 0, offset); } + /** + * Uncapitalizes a String. + * + * @param src the source String + * @return the uncapitalized String + */ + public static String uncapitalize(String src) { + if (src == null || src.isBlank()) { + return src; + } + return src.substring(0, 1).toLowerCase(Localization.getLocale()) + src.substring(1); + } + /** *

Returns the formatted server uptime.

* @@ -499,7 +448,7 @@ public final class RenderUtils { * * @param uptime the uptime in milliseconds * @param properties the format properties - * @return the formatted uptime + * @return the formatted uptime. */ @SuppressWarnings("UnnecessaryUnicodeEscape") public static String uptime(long uptime, Properties properties) { @@ -551,7 +500,7 @@ public final class RenderUtils { * Validates a credit card number using the Luhn algorithm. * * @param cc the credit card number - * @return {@code true} if the credit card number is valid + * @return {@code trude} if the credit card number is valid */ public static boolean validateCreditCard(String cc) { try { @@ -584,5 +533,4 @@ public final class RenderUtils { } return false; } - } \ No newline at end of file diff --git a/lib/src/main/java/rife/render/Rot13.java b/lib/src/main/java/rife/render/Rot13.java index d3a33c4..4bca6db 100644 --- a/lib/src/main/java/rife/render/Rot13.java +++ b/lib/src/main/java/rife/render/Rot13.java @@ -40,6 +40,6 @@ public class Rot13 implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(RenderUtils.rot13(template.getValueOrAttribute(differentiator))); + return RenderUtils.rot13(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/ShortenUrl.java b/lib/src/main/java/rife/render/ShortenUrl.java index 3ddd62e..b52c686 100644 --- a/lib/src/main/java/rife/render/ShortenUrl.java +++ b/lib/src/main/java/rife/render/ShortenUrl.java @@ -42,6 +42,6 @@ public class ShortenUrl implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(RenderUtils.shortenUrl(template.getValueOrAttribute(differentiator))); + return RenderUtils.shortenUrl(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/SwapCase.java b/lib/src/main/java/rife/render/SwapCase.java index c059a6a..270f1f6 100644 --- a/lib/src/main/java/rife/render/SwapCase.java +++ b/lib/src/main/java/rife/render/SwapCase.java @@ -41,6 +41,6 @@ public class SwapCase implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(RenderUtils.swapCase(template.getValueOrAttribute(differentiator))); + return RenderUtils.swapCase(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/TimeIso.java b/lib/src/main/java/rife/render/TimeIso.java index 9f99269..e1f0023 100644 --- a/lib/src/main/java/rife/render/TimeIso.java +++ b/lib/src/main/java/rife/render/TimeIso.java @@ -42,6 +42,6 @@ public class TimeIso implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(ZonedDateTime.now().format(RenderUtils.ISO_8601_TIME_FORMATTER)); + return ZonedDateTime.now().format(RenderUtils.ISO_8601_TIME_FORMATTER); } } diff --git a/lib/src/main/java/rife/render/Trim.java b/lib/src/main/java/rife/render/Trim.java index fb97e31..53a66e1 100644 --- a/lib/src/main/java/rife/render/Trim.java +++ b/lib/src/main/java/rife/render/Trim.java @@ -44,6 +44,6 @@ public class Trim implements ValueRenderer { if (value == null || value.isEmpty()) { return value; } - return template.getEncoder().encode(value.trim()); + return value.trim(); } } diff --git a/lib/src/main/java/rife/render/Uncapitalize.java b/lib/src/main/java/rife/render/Uncapitalize.java index bef0dfe..1e670a7 100644 --- a/lib/src/main/java/rife/render/Uncapitalize.java +++ b/lib/src/main/java/rife/render/Uncapitalize.java @@ -19,7 +19,6 @@ package rife.render; import rife.template.Template; import rife.template.ValueRenderer; -import rife.tools.StringUtils; /** *

Un-capitalizes a template value.

@@ -41,6 +40,6 @@ public class Uncapitalize implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(StringUtils.uncapitalize(template.getValueOrAttribute(differentiator))); + return RenderUtils.uncapitalize(template.getValueOrAttribute(differentiator)); } } diff --git a/lib/src/main/java/rife/render/Uppercase.java b/lib/src/main/java/rife/render/Uppercase.java index 47a7eb5..bb45bb7 100644 --- a/lib/src/main/java/rife/render/Uppercase.java +++ b/lib/src/main/java/rife/render/Uppercase.java @@ -45,6 +45,6 @@ public class Uppercase implements ValueRenderer { if (value == null || value.isBlank()) { return value; } - return template.getEncoder().encode(value.toUpperCase(Localization.getLocale())); + return value.toUpperCase(Localization.getLocale()); } } diff --git a/lib/src/main/java/rife/render/Uptime.java b/lib/src/main/java/rife/render/Uptime.java index 0353e6c..06b1371 100644 --- a/lib/src/main/java/rife/render/Uptime.java +++ b/lib/src/main/java/rife/render/Uptime.java @@ -55,13 +55,10 @@ public class Uptime implements ValueRenderer { } } - String uptime; if (template.hasAttribute(Uptime.class.getName())) { - uptime = RenderUtils.uptime((long) template.getAttribute(Uptime.class.getName()), properties); + return RenderUtils.uptime((long) template.getAttribute(Uptime.class.getName()), properties); } else { - uptime = RenderUtils.uptime(ManagementFactory.getRuntimeMXBean().getUptime(), properties); + return RenderUtils.uptime(ManagementFactory.getRuntimeMXBean().getUptime(), properties); } - - return template.getEncoder().encode(uptime); } } diff --git a/lib/src/main/java/rife/render/Year.java b/lib/src/main/java/rife/render/Year.java index c7fe2e3..d146738 100644 --- a/lib/src/main/java/rife/render/Year.java +++ b/lib/src/main/java/rife/render/Year.java @@ -43,6 +43,6 @@ public class Year implements ValueRenderer { */ @Override public String render(Template template, String valueId, String differentiator) { - return template.getEncoder().encode(ZonedDateTime.now().format(RenderUtils.ISO_8601_YEAR_FORMATTER)); + return ZonedDateTime.now().format(RenderUtils.ISO_8601_YEAR_FORMATTER); } } diff --git a/lib/src/test/java/rife/render/TestEncode.java b/lib/src/test/java/rife/render/TestEncode.java index 251b046..c5bc8bd 100644 --- a/lib/src/test/java/rife/render/TestEncode.java +++ b/lib/src/test/java/rife/render/TestEncode.java @@ -28,10 +28,6 @@ class TestEncode { var t = TemplateFactory.TXT.get("encodeBase64"); t.setValue(TestCase.FOO, TestCase.SAMPLE_TEXT); assertThat(t.getContent()).isEqualTo(t.getValue(TestCase.FOO) + ": VGhpcyBpcyBhIHRlc3Qu"); - - t = TemplateFactory.HTML.get("encodeBase64"); - t.setValue(TestCase.FOO, TestCase.SAMPLE_TEXT + " URL Encoded."); - assertThat(t.getContent()).as("with URL encoding").contains("VGhpcyBpcyBhIHRlc3QuIFVSTCBFbmNvZGVkLg%3D%3D"); } @Test @@ -54,11 +50,6 @@ class TestEncode { var t = TemplateFactory.TXT.get("encodeJs"); t.setAttribute(TestCase.FOO, "'\"\\/"); assertThat(t.getContent()).isEqualTo("\\'\\\"\\\\\\/"); - - t = TemplateFactory.HTML.get("encodeJs"); - t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"'); - assertThat(t.getContent()).as("with unicode") - .isEqualTo("\\u005C\\u0022\\u0054\\u0068\\u0069\\u0073\\u0020\\u0069\\u0073\\u0020\\u0061\\u0020\\u0074\\u0065\\u0073\\u0074\\u002E\\u005C\\u0022"); } @Test @@ -66,10 +57,6 @@ class TestEncode { var t = TemplateFactory.JSON.get("encodeJson"); t.setAttribute(TestCase.FOO, "This is a \"•test\""); assertThat(t.getContent()).isEqualTo("{\n \"foo\": \"This is a \\\"\\u2022test\\\"\"\n}"); - - t = TemplateFactory.HTML.get("encodeJson"); - t.setAttribute(TestCase.FOO, "\"\""); - assertThat(t.getContent()).as("with html").isEqualTo("\\"<test>\\""); } @Test @@ -93,11 +80,6 @@ class TestEncode { t.setAttribute(TestCase.FOO, TestCase.SAMPLE_TEXT); assertThat(t.getContent()).isEqualTo( "\\u0054\\u0068\\u0069\\u0073\\u0020\\u0069\\u0073\\u0020\\u0061\\u0020\\u0074\\u0065\\u0073\\u0074\\u002E"); - - t = TemplateFactory.HTML.get("encodeUnicode"); - t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"'); - assertThat(t.getContent()).as("with js") - .contains("'\\\\u0022\\\\u0054\\\\u0068\\\\u0069\\\\u0073\\\\u0020\\\\u0069\\\\u0073\\\\u0020\\\\u0061\\\\u0020\\\\u0074\\\\u0065\\\\u0073\\\\u0074\\\\u002E\\\\u0022'"); } @Test @@ -105,11 +87,6 @@ class TestEncode { var t = TemplateFactory.HTML.get("encodeUrl"); t.setAttribute(TestCase.FOO, "a test &"); assertThat(t.getContent()).isEqualTo("a test &"); - - t = TemplateFactory.HTML.get("encodeUrlwithUnicode"); - t.setAttribute(TestCase.FOO, "a=test"); - assertThat(t.getContent()).as("with unicode") - .contains("https://foo.com/\\u0061\\u0025\\u0033\\u0044\\u0074\\u0065\\u0073\\u0074"); } @Test diff --git a/lib/src/test/java/rife/render/TestFormat.java b/lib/src/test/java/rife/render/TestFormat.java index 945e33f..cf7cdb9 100644 --- a/lib/src/test/java/rife/render/TestFormat.java +++ b/lib/src/test/java/rife/render/TestFormat.java @@ -27,7 +27,7 @@ class TestFormat { void testAbbreviate() { var t = TemplateFactory.HTML.get("abbreviate"); t.setAttribute(TestCase.FOO, TestCase.SAMPLE_TEXT); - assertThat(t.getContent()).as("activate.html").endsWith("…").hasSize(19); + assertThat(t.getContent()).as("activate.html").endsWith("…").hasSize(12); t = TemplateFactory.TXT.get("abbreviate"); t.setAttribute(TestCase.FOO, TestCase.SAMPLE_TEXT); @@ -52,8 +52,7 @@ class TestFormat { var t = TemplateFactory.HTML.get("mask"); var foo = "374380141731053"; t.setAttribute(TestCase.FOO, foo); - assertThat(t.getContent()).as("mask.html") - .isEqualTo("3743•••••••••••"); + assertThat(t.getContent()).as("mask.html").isEqualTo("3743•••••••••••"); t = TemplateFactory.TXT.get("mask"); t.setAttribute(TestCase.FOO, foo); @@ -96,7 +95,7 @@ class TestFormat { t = TemplateFactory.HTML.get("uptime"); t.setAttribute(Uptime.class.getName(), 547800300076L); assertThat(t.getContent()).as("uptime.html") - .isEqualTo("17 années, 4 mois, 2 semaines, 1 jour, 6 heures, 45 minutes"); + .isEqualTo("17 années, 4 mois, 2 semaines, 1 jour, 6 heures, 45 minutes"); t.setAttribute(Uptime.class.getName(), 120000L); assertThat(t.getContent()).as("uptime.html: 2 min").isEqualTo("2 minutes"); diff --git a/lib/src/test/java/rife/render/TestRenderUtils.java b/lib/src/test/java/rife/render/TestRenderUtils.java index 6854bf5..f0f55c5 100644 --- a/lib/src/test/java/rife/render/TestRenderUtils.java +++ b/lib/src/test/java/rife/render/TestRenderUtils.java @@ -19,8 +19,6 @@ package rife.render; import org.junit.jupiter.api.Test; -import java.util.Properties; - import static org.assertj.core.api.Assertions.assertThat; class TestRenderUtils { @@ -38,18 +36,9 @@ class TestRenderUtils { } @Test - void testEncode() { - var p = new Properties(); - p.put(RenderUtils.ENCODING_PROPERTY, "html"); - assertThat(RenderUtils.encode("", p)).as("html").isEqualTo("<a test &>"); - p.put(RenderUtils.ENCODING_PROPERTY, "js"); - assertThat(RenderUtils.encode("\"test'", p)).as("js").isEqualTo("\\\"test\\'"); - p.put(RenderUtils.ENCODING_PROPERTY, "unicode"); - assertThat(RenderUtils.encode("test", p)).as("unicode").isEqualTo("\\u0074\\u0065\\u0073\\u0074"); - p.put(RenderUtils.ENCODING_PROPERTY, "url"); - assertThat(RenderUtils.encode("a = test", p)).as("url").isEqualTo("a%20%3D%20test"); - p.put(RenderUtils.ENCODING_PROPERTY, "xml"); - assertThat(RenderUtils.encode("Joe's Café & Bar", p)).as("xml").isEqualTo("Joe's Café & Bar"); + void testCapitalize() { + assertThat(RenderUtils.capitalize("a")).isEqualTo("A"); + assertThat(RenderUtils.capitalize("")).as("empty").isEqualTo(""); } @Test @@ -89,6 +78,12 @@ class TestRenderUtils { assertThat(RenderUtils.swapCase(SAMPLE_GERMAN)).isEqualTo("mÖCHTEN sIE EIN PAAR äPFEL?"); } + @Test + void testUcapitalize() { + assertThat(RenderUtils.uncapitalize("A")).isEqualTo("a"); + assertThat(RenderUtils.uncapitalize("")).as("empty").isEqualTo(""); + } + @Test void testValidateCreditCard() { assertThat(RenderUtils.validateCreditCard("4505 4672 3366 6430")).as("visa").isTrue(); diff --git a/lib/src/test/resources/templates/encodeBase64.html b/lib/src/test/resources/templates/encodeBase64.html deleted file mode 100644 index 804270c..0000000 --- a/lib/src/test/resources/templates/encodeBase64.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/lib/src/test/resources/templates/encodeJs.html b/lib/src/test/resources/templates/encodeJs.html deleted file mode 100644 index ed9dd6f..0000000 --- a/lib/src/test/resources/templates/encodeJs.html +++ /dev/null @@ -1 +0,0 @@ -encoding=unicode \ No newline at end of file diff --git a/lib/src/test/resources/templates/encodeJson.html b/lib/src/test/resources/templates/encodeJson.html deleted file mode 100644 index 17b675b..0000000 --- a/lib/src/test/resources/templates/encodeJson.html +++ /dev/null @@ -1 +0,0 @@ -encoding=html \ No newline at end of file diff --git a/lib/src/test/resources/templates/encodeUnicode.html b/lib/src/test/resources/templates/encodeUnicode.html deleted file mode 100644 index f1ee916..0000000 --- a/lib/src/test/resources/templates/encodeUnicode.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/lib/src/test/resources/templates/encodeUrlwithUnicode.html b/lib/src/test/resources/templates/encodeUrlwithUnicode.html deleted file mode 100644 index b59f98b..0000000 --- a/lib/src/test/resources/templates/encodeUrlwithUnicode.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file