Is anyone else using the `route` helper function i...
# box-products
j
Is anyone else using the
route
helper function in cbPlaywright on Windows? For me, I'm just passing in "/" — so `navigate( page, route( "/" ) );`— and it's giving an error "*Illegal char <:> at index 4: http://127.0.0.1:63337\/*". For some reason, it's blowing up because of the colon, which obviously is a problem since we're talking about urls here. I've traced it to the definition of the
route
method in
models/PlaywrightMixins.cfm
of the cbPlaywright project. The return value of the method,
return variables.javaPaths.get( baseURL, javacast( "String[]", pathArray ) ).toString();
, is calling
javaPaths.get
which is itself an object instantiated with the following
variables.javaPaths = createObject( "java", "java.nio.file.Paths" );
.
baseURL
is just my URL -
<http://127.0.0.1:63337>
- and
pathArray
is just
["/"]
. There is no problem with the
javacast
portion of the line. The error is coming from the
javaPaths.get
call and specifically the
baseURL
value that is being passed in with the colon. The most I've found is here which also is referencing
java.nio.file.Path
, and the explanation found here, unless I'm wrong (which is very possible), suggests that this code in the
route
helper method won't work on Windows. I'm on v1.0.3 of cbPlaywright. I tried both ACF2021u5 and Lucee 5.3.10. Running v11.0.18 of Java and Windows 11.
z
what's the lucee stacktrace look like?
j
Copy code
lucee.runtime.exp.NativeException: Illegal char <:> at index 4: <http://127.0.0.1:54081>\/
	at sun.nio.fs.WindowsPathParser.normalize(Unknown Source)
	at sun.nio.fs.WindowsPathParser.parse(Unknown Source)
	at sun.nio.fs.WindowsPathParser.parse(Unknown Source)
	at sun.nio.fs.WindowsPath.parse(Unknown Source)
	at sun.nio.fs.WindowsFileSystem.getPath(Unknown Source)
	at java.nio.file.Paths.get(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at lucee.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:56)
	at lucee.runtime.java.JavaObject.call(JavaObject.java:265)
	at lucee.runtime.java.JavaObject.call(JavaObject.java:287)
	at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787)
	at lucee.runtime.PageContextI
Here it is for ACF:
Copy code
java.nio.file.InvalidPathException: Illegal char <:> at index 4: <http://127.0.0.1:63337>\/
	at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
	at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
	at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
	at java.base/java.nio.file.Path.of(Path.java:147)
	at java.base/java.nio.file.Paths.get(Paths.java:69)
	at java.base/jdk.internal.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:106)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4254)
	at coldfusion.runtime.CfJspPage.
z
why is that code trying to writing a url as a filename, that's never going to work due to such characters?
j
Not sure! I'll try to dig a bit deeper.
The original function with the
javaPaths.get
call in the last line causing the error:
Copy code
public string function route() {
		var baseURL = CGI.HTTPS == "on" ? "https://" : "http://" & CGI.HTTP_HOST;
		var pathArray = [];
		for ( var currentKey in arguments ){
			pathArray.append( arguments[currentKey] );
		}
		return variables.javaPaths.get( baseURL, javacast( "String[]", pathArray ) ).toString();
}
I wonder if this could be updated to something like so (only change is to that last line):
Copy code
public string function route() {
		var baseURL = CGI.HTTPS == "on" ? "https://" : "http://" & CGI.HTTP_HOST;
		var pathArray = [];
		for ( var currentKey in arguments ){
			pathArray.append( arguments[currentKey] );
		}
		return pathArray.reduce( ( concatenator, pathPart ) => concatenator & "/" & pathPart, baseUrl );
}
I could be missing some of the finer nuances of what was going on here. And, of course, passing in the slash in
route( '/'
or
route( "/users", "joe" )
wouldn't work anymore. You would just want
route()
or
route( "users", "joe")
. But again, I could be, and likely am, missing something about what was meant to be happening here. Just thinking out loud. At this point, it appears to be a bug so I'll go ahead and submit something when I get a few.
Submitted an issue for the cbPlaywright repo here.