php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31641 empty string returned as single space
Submitted: 2005-01-21 17:12 UTC Modified: 2005-01-25 23:11 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: tomasz at biznespolska dot pl Assigned: iliaa (profile)
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.10 OS: win32
Private report: No CVE-ID: None
 [2005-01-21 17:12 UTC] tomasz at biznespolska dot pl
Description:
------------
I'd like to continue thread:
http://bugs.php.net/bug.php?id=25777
Because it's already closed I wasn't able to add my comments there.

By disabling rtriming of text fields, new bug was introduced - empty strings are returned as single space. I know that is because of MS DBLib, but there is no problem to fix that in PHP.

It is very rare that someone will store in database single space, but storing empty spaces is very common. So in my opinion most common usage should be considered.
For example: if ( empty($text_from_db) ) { // do something }

In my opinion ' ' should replaced by ''. 

I don't how to submit this to CVS, so I put it here:

ext/mssql/mssql.c line 805:

case SQLTEXT: {
	int length;
	char *data = charcol(offset);

	length=dbdatlen(mssql_ptr->link,offset);
#if ilia_0
	while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace */
		length--;
	}
#endif
	if ( length==1 && data[0]==' ' ) { /* single space to empty string */
		length=0;
	}
	
	Z_STRVAL_P(result) = estrndup(data,length);
	Z_STRLEN_P(result) = length;
	Z_TYPE_P(result) = IS_STRING;
	break;
}


Reproduce code:
---------------
//mssql_connect(...);
var_dump(mssql_fetch_row(mssql_query("SELECT ''")));

Expected result:
----------------
array(1) { [0]=> string(0) "" }

Actual result:
--------------
array(1) { [0]=> string(1) " " }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-21 17:20 UTC] tomasz at biznespolska dot pl
Ofcourse I mean "empty strings" not "empty spaces". Should be: 
"It is very rare that someone will store in database single space, but storing empty string is very common."
 [2005-01-22 15:05 UTC] sniper@php.net
Ilia, you 'broke' it.. :)

 [2005-01-25 23:11 UTC] iliaa@php.net
As the original report explains, this is a bug in the interface library and not PHP. The old behaviour results in data mangling (space stripping).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 20:01:31 2024 UTC