Cfhttp issue - URGENT!

Hello all. First, some specs…

Lucee version 6.2.0.321, although only upgraded last night (from version 6.1.x I believe) while trying to resolve the issue that follows.
Apache Tomcat/9.0.89
11.0.22 (Eclipse Adoptium) 64bit
Windows Server 2016 (10.0) 64bit

I am developing an application that calls and consumes the Microsoft Graph API. I have been able to obtain an access token and have made numerous successful calls to the API.

My problem comes in when I try to make a call to the API using cfhttp and the $count URL segment (more on that here). The returned cfhttp structure returns a filecontent member that appears to be just the number, as is expected from this call…

The problem is when I try to consume the filecontent. For example…
<cfset num = LSParseNumber(cfhttp.filecontent)>

…throws the following exception…

…and parseNumber throws…


Notice what appears to be an extra space in the parseNumber exception message, between “Character” and “is”.

I have tried a number of things and have spent many hours trying to find the cause and solution to this problem. I am hoping (against hope, it feels like) that someone here may have the wisdom that I do not. I am up against a deadline, and am concurrently trying to develop a workaround. If anyone can provide some quick feedback, that would be wonderful!

Have you tried something like:

<cfset num = LSParseNumber(cfhttp.filecontent + 0)>

Other possibility may be some hidden / LF CR / unprintable character that you need to strip out.

Since the values of the API you are receiving should be a JSON, what happens when you 'just use

<cfset number = deserializeJSON(mycfhttpvar.filecontent)>

?

In this case, even testing it with Microsoft’s own Graph Explorer, it returns just the number in text/plain format. I was surprised.

Hello @psarin and thank you for your reply.

I tried your code example in my situation, and it returned…

So then I tried the following (I’m sorry, I can’t get it to display in the syntactically colorful way)…

<cfset count = LSParseNumber(reReplace(requestResult.filecontent, "[^0-9]", "", "all"))>

This in fact returned a number! Thankfully, I knew I was dealing with a numeric value and that made the RegEx really simple!

I’m still not entirely sure what extra little piece of “invisible” information was added, or how it came to be, but the RegEx stripped it out.

Thank you!

Ok, you mean the server heder content-type is set to html/text then and not application/json, right? Then that is an api issue. I’m not at my notebook right now, but I’d try it anyway and also as a second option trimming it before consuming anything.

Or are just saying it is of text/html becaue it is not sent as a key/value pair?

I had tried the Trim() function. It did not do the trick. Thanks for the reply.

have you tried deserializeJSON? Just wondering.

@andreas, correct, the value is not sent as JSON at all, just plain text with the header Content-Type text/plain.

If I try…
<cfset count = deserializeJSON(cfhttp.filecontent)>

1 Like

Looks to me as an API issue. If so, I’d notify Microsoft about it.

Does the following work?
<cfset count = LSParseNumber(val(requestResult.fileContent))>

Or indeed, just using val()? I gues it depend on what sort of things are going to be returned from the API…

@mbuckman that’s clearly a regression, please file a bug

https://luceeserver.atlassian.net/

as trycf is already on 6.2, you you share a repo?

really strange, Lucee does a trim internally before using the parser.
we use a different parser because we switched from double to BigDecimal numbers by default.
But the parser used is from the JVM itself, also the message comes from the JVM. @mbuckman can you please copy/paste the exception message here or better write it to a file with charset UTF-8 and attach the file here

fileWrite("test.txt",cfhttp.filecontent,"UTF-8");
1 Like

this is the exception thrown in this case

throw new NumberFormatException("Character " + c
                            + " is neither a decimal digit number, decimal point, nor"
                            + " \"e\" notation exponential mark.");

as @mbuckman has already pointed out “c” is empty

okay i can reproduce the issue with this (in Java)


	public static void main(String[] args) throws CasterException {
		// Test cases with various invisible characters
		print.e(toBigDecimal("17")); // Normal case, should work
		print.e(toBigDecimal("17\u200B")); // Zero-width space
		print.e(toBigDecimal("1\u00A07")); // Non-breaking space
		print.e(toBigDecimal("1\u20087")); // Punctuation space
		print.e(toBigDecimal("17\uFEFF")); // Zero-width no-break space (BOM)
		print.e(toBigDecimal("17\u200C")); // Zero-width non-joiner
		print.e(toBigDecimal("17 ")); // Regular space at the end (should be trimmed)
		print.e(toBigDecimal(" 17")); // Regular space at the beginning (should be trimmed)

		// Also test with your actual problematic string if possible
		// For example, this might be coming from a file or user input
	}

issue is fixed
https://luceeserver.atlassian.net/browse/LDEV-5354

@mbuckman would be great if you could give that version a try (details in the ticket)

2 Likes

Sorry everyone. I just saw the activity on this post. I will try to spin up a VM and give it a shot this weekend, maybe with both 6.1 and 6.2.1.45-SNAPSHOT. Thanks for the diagnostic work, @micstriit!

1 Like