Regression?: String concatenation causes hard break in

Windows, commandbox 5.4.2

I need to create unique contactCodes via API. The API is picky about strings vs numerics. Strings must be single-quoted, numeric can’t be. I’m using hyper to make these requests. In the code below, if I don’t try to enclose the padded code using “’#()#’”, it works. If I do it this way, I get the following error:

var contactCode = &;
var count = 0;

do {
	res = getContact( { ContactCode: "'#(contactCode &= ((count) ? numberFormat(count, "09") : ""))#'" } );
} while ( res.len())


function getContact( contactParams ) {
	var params = {
		"$filter" : contactParams.reduce((o,k,v)=>{ return o & k & " eq " & v },""),
		"$select" : "ContactID,ContactName,ContactCode,FirstName,LastName,DeliveryName,Company,EMail,ContactCode,ContactType,OwnerID",
		"$expand" : "ContactAddresses,ContactPhones"

	return send( {
		queryParams : params,
		method      : "GET",
		url         : "/contacts"
	} );


@Daemach Your example is uneccessarily complex. I can reproduce the error with just this code:

"'#foo &= ""#'"

I’d enter a ticket.

While simplfying your example, I also ran into this odd error

foo &= (1 ? "" : "")

produces this error:

lucee.runtime.exp.NativeException: java.lang.Object cannot be cast to lucee.runtime.type.scope.Threads
 at lucee.runtime.type.scope.UndefinedImpl.getScopeFor(
 at lucee.runtime.interpreter.VariableInterpreter.getVariableReference(
 at lucee.runtime.op.Operator.unaryPreConcat(
 at page$cf$

That probably deserves a separate ticket as well.

1 Like

Is this trying trying to output a variable (that doesn’t exist) called foo &= " ?

Or is it trying to be clever and set foo to something if it doesn’t exist ? In an odd way…

So the title is a bit scary but it’s fine. I mean, not fine but ‘all right unless you are doing something like rendering untrusted variable names or weird code syntax tricks’

And the work around is to make the bit between the hash marks from the original much less complicated ?

FYI gives the same bytecode dump error :slight_smile:

Not sure what you’re asking. &= is the concat and set operator. i.e.

str = 'brad'
str &= 'wood'
// assert, str now equals "bradwood"

Perhaps you were thrown off by the fact foo wasn’t declared prior. That would be an issue if the code compiled :slight_smile: it would throw an error that the variable foo didn’t exist. But since the code doesn’t even compile, I didn’t even bother initializing the variable in the example as it wasn’t necessary to the repro case.

The ? in my second example is just a ternary statement

boolean ? 'if true' : 'if false' 

Since you didn’t use any code blocks, I’m not quite sure if you were just using ? to ask a question or if you were referring to that part of the code :wink:

It’s mostly related to LDEV-906 Unexpected use of &= causes error or crashes server

It’s not regression because it throws the same error in old lucee versions too. @Daemach does it worked for you before in any lucee previous versions?

That makes sense

I don’t remember making a silly mistake like that in previous versions :wink: That was the reason for the ? in the title.

And Brad is right about the overcomplex example, but it was easy to copy/paste.

1 Like