mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-11-22 17:26:45 +00:00
Fix error when shorturl is empty
This commit is contained in:
parent
58e956b2ef
commit
769db79fde
@ -18,13 +18,17 @@ public class Routes {
|
|||||||
|
|
||||||
public static String addUrl(Request req, Response res) {
|
public static String addUrl(Request req, Response res) {
|
||||||
var body = req.body();
|
var body = req.body();
|
||||||
var split = body.split(";");
|
if (body.endsWith(";")) {
|
||||||
String longUrl = split[0];
|
body = body + "$";
|
||||||
String shortUrl = split[1];
|
|
||||||
|
|
||||||
if (shortUrl == null || shortUrl.isBlank()) {
|
|
||||||
shortUrl = Utils.randomString();
|
|
||||||
}
|
}
|
||||||
|
var split = body.split(";");
|
||||||
|
|
||||||
|
String longUrl = split[0];
|
||||||
|
|
||||||
|
if (split[1].equals("$")) {
|
||||||
|
split[1] = Utils.randomString();
|
||||||
|
}
|
||||||
|
String shortUrl = split[1];
|
||||||
|
|
||||||
if (Utils.validate(shortUrl)) {
|
if (Utils.validate(shortUrl)) {
|
||||||
return urlRepository.addUrl(longUrl, shortUrl);
|
return urlRepository.addUrl(longUrl, shortUrl);
|
||||||
|
Loading…
Reference in New Issue
Block a user