diff --git a/README.md b/README.md index 447237b..78c7aae 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,14 @@ Via Maven pl.ksdev slugify - 0.2 + 0.3 ``` Via Gradle ```groovy -compile 'pl.ksdev:slugify:0.2' +compile 'pl.ksdev:slugify:0.3' ``` ## Usage @@ -45,5 +45,5 @@ The MIT License (MIT). Please see [License File](LICENSE) for more information. [ico-coveralls]: https://img.shields.io/coveralls/github/ksdev-pl/slugify.svg?style=flat-square [link-travis]: https://travis-ci.org/ksdev-pl/slugify -[link-maven]: http://search.maven.org/#artifactdetails%7Cpl.ksdev%7Cslugify%7C0.2%7Cjar +[link-maven]: http://search.maven.org/#artifactdetails%7Cpl.ksdev%7Cslugify%7C0.3%7Cjar [link-coveralls]: https://coveralls.io/github/ksdev-pl/slugify?branch=master \ No newline at end of file diff --git a/pom.xml b/pom.xml index d593d15..4332ef7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 pl.ksdev slugify - 0.2 + 0.3 jar Slugify diff --git a/src/main/java/pl/ksdev/slugify/SimpleSlugService.java b/src/main/java/pl/ksdev/slugify/SimpleSlugService.java index 50f5d49..826ba1f 100644 --- a/src/main/java/pl/ksdev/slugify/SimpleSlugService.java +++ b/src/main/java/pl/ksdev/slugify/SimpleSlugService.java @@ -217,9 +217,7 @@ public SimpleSlugService() { */ public SimpleSlugService(int maxSlugLength) { if (maxSlugLength <= 0) { - throw new IllegalArgumentException( - "maxSlugLength must be greater than zero" - ); + throw new IllegalArgumentException("maxSlugLength must be > 0"); } this.maxSlugLength = maxSlugLength; @@ -253,13 +251,11 @@ public String slugify(String text) { } // Trim dashes - if (slug.length() > 0) { - if (slug.charAt(0) == '-') { - slug.deleteCharAt(0); - } - if (slug.charAt(slug.length() - 1) == '-') { - slug.deleteCharAt(slug.length() - 1); - } + if (slug.length() > 0 && slug.charAt(0) == '-') { + slug.deleteCharAt(0); + } + if (slug.length() > 0 && slug.charAt(slug.length() - 1) == '-') { + slug.deleteCharAt(slug.length() - 1); } return slug.toString(); diff --git a/src/test/java/pl/ksdev/slugify/SimpleSlugServiceTest.java b/src/test/java/pl/ksdev/slugify/SimpleSlugServiceTest.java index f06f67d..958eac5 100644 --- a/src/test/java/pl/ksdev/slugify/SimpleSlugServiceTest.java +++ b/src/test/java/pl/ksdev/slugify/SimpleSlugServiceTest.java @@ -36,14 +36,44 @@ public void shouldReturnEmptyString() { // given String text1 = ""; String text2 = " @ \n#* \\ $/&) !(&*\r# . .."; + String text3 = "*****************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************" + + "****************************************************************"; // when - String result1 = new SimpleSlugService().slugify(""); - String result2 = new SimpleSlugService().slugify(""); + String result1 = new SimpleSlugService().slugify(text1); + String result2 = new SimpleSlugService().slugify(text2); + String result3 = new SimpleSlugService().slugify(text3); // then assertEquals("", result1); assertEquals("", result2); + assertEquals("", result3); } @Test