Bug - Fixed Plus sign + being stripped from cli commands sent from relay gCLI

Rinn

Developer
r19944

I'm seeing the plus sign + character being removed from any commands I send in the relay browser gCLI. This doesn't seem to affect the cli from the java interface.

For example if I send the command print a+b in the relay browser I get the following output

Code:
[COLOR=olive][FONT=arial]> print a b[/FONT][/COLOR]

[COLOR=#000000][FONT=arial]a b[/FONT][/COLOR]

Sending the same from the java interface works fine:

Code:
[COLOR=olive]> print a+b[/COLOR]

a+b
 

Veracity

Developer
Staff member
The plus sign is the URL encoding for a space. Sending a plus sign in a URL requires that it be encoded as %2B

Is this the thing that puts the cli into (or replacing) the chat window?
I have, literally, never used that in my life.
 

Veracity

Developer
Staff member
src/relay/cli.html has the following JavaScript:

Code:
	function submitCommand()
	{
		var display = document.getElementById( "CmdWindow" );
		var command = document.cmdform.cmd.value;
		document.cmdform.cmd.value = "";

		if ( command == "" )
			return true;

		commandCount = commands.push( command );

		if ( command == "clear" || command == "cls" || command == "reset" )
		{
			display.innerHTML = "";
			return true;
		}

		display.style.width = initwidth;
		display.scrollTop = display.scrollHeight;

		var httpObject = getHttpObject();
		if ( !httpObject )
			return true;

		executed = false;

		httpObject.open( "GET", "/KoLmafia/submitCommand?cmd=" + URLEncode( command ) + "&MAFIAHIT", true );
		httpObject.send( "" );

		document.cmdform.cmd.focus();
		return true;
	};
which does URL encode the command sent back.
Perhaps it is decoded twice at the other end?
 

Veracity

Developer
Staff member
It is decoded twice.

RelayRequest.handleCommand:

Code:
		if ( path.endsWith( "submitCommand" ) )
		{
			submitCommand( this.getFormField( "cmd" ) );
			this.pseudoResponse( "HTTP/1.1 200 OK", "" );
		}
GenericRequest.getFormField calls GenericRequest.findField:

Code:
			// Chat was encoded as ISO-8859-1, so decode it that way.
			String charset = this.isChatRequest ? "ISO-8859-1" : "UTF-8";
			return GenericRequest.decodeField( value, charset );
RelayRequest.submitCommand:

Code:
			CommandDisplayFrame.executeCommand( GenericRequest.decodeField( command ) );
 

Rinn

Developer
Thanks, I've been using the relay browser almost exclusively right now, I've been running mafia in --CLI mode in a docker container with a relay server running and connecting to it remotely through a reverse proxy.
 

fredg1

Member
Since 2 days ago, clicking on the "Solve!" button in the volcano submits "volcano+solve" instead of "volcano solve" to the GCLI, is this an issue related to this fix?
 

Veracity

Developer
Staff member
Yes.

The Chess Puzzle in The Rabbit Hole has a Solve! button with a similar problem. Both the Volcano and Chess Puzzle submit a two word command which is encoded by the browser. So those, unlike commands which are submitted by an HTML <a> tag, really do need to be decoded twcie: once to get rid of the browser's encoding, and once to get rid of the command's encoding.

Revision 19959 fixes that issue. Tested with the Chess Puzzle.
 
Top