VbFcgi icon indicating copy to clipboard operation
VbFcgi copied to clipboard

How to handle query parameters with no "=" separator?

Open jpbro opened this issue 7 years ago • 1 comments

Thought I pose this as a question in case anyone out there had an insights/preferences.

Consider the following URL:

http://localhost/myapp.fcgi?test

Where test is the query string.

In the current VbFcgi implementation, test is treated as a default parameter value. Calling CHttpQueryParams.DefaultValue returns test, and calling CHttpQueryParams.ValuesByKey("") returns a CHttpQueryParamValues object with a single value of test.

I'm thinking it might be better to treat test as a "flag" and use it as a key instead of a value. So calling CHttpQueryParams.Exists("test") would return True and calling CHttpQueryParams.ValuesByKey("test") would return a CHttpQueryParamValues object with zero values.

Perhaps the best of both worlds would be an option property to let users decide which approach to take based on the needs of their FCGI applications?

jpbro avatar Dec 29 '17 18:12 jpbro

Both ASP Classic and PHP treats ?test as a key with a zero length string value.

PHP:

<?php
echo $_SERVER["QUERY_STRING"]."<br>";
if(isset($_GET["test"]) && gettype($_GET["test"]) == "string" && $_GET["test"] == "")
	echo "OK";

ASP Classic:

<%
Response.Write Request.ServerVariables("QUERY_STRING") & "<br>"
If Request.QueryString("test").Count = 1 And VarType(Request.QueryString("test")) = vbString And Request.QueryString("test") = "" Then
	Response.Write "OK"
End If
%>

Both prints:

test
OK

I would go with this approach by default, but providing an option to change the behavior would also be good.

skacurt avatar Feb 16 '19 13:02 skacurt