JPro-one / jpro-routing

Small web-framework for JPro
https://www.jpro.one
Apache License 2.0
6 stars 0 forks source link

If URL contains & symbol (encoded with %26), error happens #13

Closed ctoabidmaqbool closed 1 year ago

ctoabidmaqbool commented 1 year ago

Hi Devs, If URL contains & symbol, weather it's in encoded form e.g. %20, error happens:

oto: /info?name=Abid%26Aqib
Error while loading the path http://localhost:8070/info?name=Abid%26Aqib
scala.MatchError: [Ljava.lang.String;@22b2cbb3 (of class [Ljava.lang.String;)
    at one.jpro.routing.Request$.$anonfun$fromString$1(Request.scala:53)
    at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:285)
    at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
    at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
    at scala.collection.TraversableLike.map(TraversableLike.scala:285)
    at scala.collection.TraversableLike.map$(TraversableLike.scala:278)
    at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:198)
    at one.jpro.routing.Request$.fromString(Request.scala:52)
    at one.jpro.routing.RouteNode.route(RouteNode.scala:36)
    at one.jpro.routing.sessionmanager.SessionManager.getView(SessionManager.scala:75)
    at one.jpro.routing.sessionmanager.SessionManager.getView$(SessionManager.scala:73)
    at one.jpro.routing.sessionmanager.SessionManagerWeb.getView(SessionManagerWeb.scala:13)
    at one.jpro.routing.sessionmanager.SessionManager.gotoURL(SessionManager.scala:54)
    at one.jpro.routing.sessionmanager.SessionManager.gotoURL$(SessionManager.scala:49)
    at one.jpro.routing.sessionmanager.SessionManagerWeb.gotoURL(SessionManagerWeb.scala:13)
    at one.jpro.routing.sessionmanager.SessionManager.gotoURL(SessionManager.scala:46)
    at one.jpro.routing.sessionmanager.SessionManager.gotoURL$(SessionManager.scala:42)
    at one.jpro.routing.sessionmanager.SessionManagerWeb.gotoURL(SessionManagerWeb.scala:13)
    at one.jpro.routing.sessionmanager.SessionManagerWeb$$anon$2.callback(SessionManagerWeb.scala:117)
    at com.jpro.WebAPIImpl$WebAPIImpl.$anonfun$registerJavaFunction$1(WebAPIImpl.scala:213)
    at com.jpro.WebAPIImpl$WebAPIImpl.$anonfun$registerJavaFunction$1$adapted(WebAPIImpl.scala:213)
    at com.jpro.WebAPIImpl$WebAPIImpl.$anonfun$setCommandResult$1(WebAPIImpl.scala:112)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at simplefx.cores.interfaces.parts.testing.CoreTesting.inFX(CoreTesting.scala:21)
    at simplefx.cores.interfaces.parts.testing.CoreTesting.inFX$(CoreTesting.scala:18)
    at simplefx.cores.standard.Core.inFX(Core.scala:9)
    at com.jpro.WebAPIImpl$WebAPIImpl.setCommandResult(WebAPIImpl.scala:111)
    at com.jpro.internal.communicator.ViewImpl$$anonfun$receiveInput$5.applyOrElse(ViewImpl.scala:240)
    at com.jpro.internal.communicator.ViewImpl$$anonfun$receiveInput$5.applyOrElse(ViewImpl.scala:237)
    at scala.collection.immutable.List.collect(List.scala:315)
    at com.jpro.internal.communicator.ViewImpl.receiveInput(ViewImpl.scala:237)
    at com.jpro.internal.server.ViewSerializerActor$$anonfun$receive$2.$anonfun$applyOrElse$4(ViewSerializerActor.scala:95)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    at simplefx.cores.standard.parts.CoreTimeEvent$$anon$3.run(CoreTimeEvent.scala:62)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
    at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
    at java.base/java.lang.Thread.run(Thread.java:833)

Sample code:

package com.jpro.hellojpro;

import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import one.jpro.routing.LinkUtil;
import one.jpro.routing.Route;
import one.jpro.routing.RouteApp;
import one.jpro.routing.View;
import simplefx.experimental.parts.FXFuture;

import static one.jpro.routing.RouteUtils.redirect;

public class App extends RouteApp {
    private Stage pStage;

    @Override
    public void start(Stage pStage) {
        this.pStage = pStage;
        super.start(pStage);
    }

    @Override
    public Route createRoute() {
        return Route.empty()
                .and(redirect("/", "/info"))
                .and(r -> {
                    System.out.println("path: " + r.path());
                    System.out.println("prams empty: " + r.queryParameters().isEmpty());

                    if (r.path().equals("/info") && r.queryParameters().contains("name")) {
                        return FXFuture.unit(new InfoPage((pStage), r.queryParameters().get("name").get()));
                    } else if (r.path().equals("/info")) {
                        return FXFuture.unit(new InfoPage((pStage)));
                    }

                    return FXFuture.unit(null);
                });
    }
}

class InfoPage extends View {
    private Stage pStage;

    public InfoPage(Stage pStage) {
        this.pStage = pStage;
    }

    public InfoPage(Stage pStage, String q) {
        this.pStage = pStage;
        System.out.println("route contans, q: " + q);
    }

    @Override
    public String title() {
        return "Sample JPro Page";
    }

    @Override
    public String description() {
        return "This is a simple page where JPro testing done.";
    }

    @Override
    public Node content() {
        VBox root = new VBox(10);
        root.setAlignment(Pos.CENTER);
        root.setPrefSize(500, 1000);

        Label lblText = new Label("Home");
        LinkUtil.setLink(lblText, "/");

        Label lblText2 = new Label("Info with Parm");
        LinkUtil.setLink(lblText2, "/info?name=Abid&Aqib".replaceAll(" ", "%20").replaceAll("&", "%26"));

        root.getChildren().addAll(lblText, lblText2);

        return root;
    }
}

How to encode URL: https://www.w3schools.com/tags/ref_urlencode.ASP

FlorianKirmaier commented 1 year ago

I've made a new 0.15.0-SNAPSHOT build, which should fix the issue. Can you test it, and verify it?

ctoabidmaqbool commented 1 year ago

@FlorianKirmaier Thanks, your latest build of JPro Routing e.g. 0.15.0-SNAPSHOT fix the above issue of & operator.

I have to delete manually old snapshot files e.g. D:\.my-gradle\caches\modules-2\files-2.1\one.jpro\jpro-routing-core\0.15.0-SNAPSHOT so that gradle download new one. Is there any method in gradle which auto this task e.g. check for new update of libs online if any.

FlorianKirmaier commented 1 year ago

--refresh-dependencies is supposed to work, but i think it's not reliable. Usually, i have a "deleteCache.sh" script in my projects, but it's limited to unix https://github.com/JPro-one/jpro-routing/blob/master/deleteCache.sh