commandbox-cfformat icon indicating copy to clipboard operation
commandbox-cfformat copied to clipboard

cfquery in tag islands with conditional cfqueryparams

Open TheRealAgentK opened this issue 5 years ago • 2 comments

I found another cfquery-inside-of-tag-islands problem.

This is what I have pre-formatting:

        <cfquery name="fghfgf" datasource="#dsn#">
            UPDATE fghfghfg
            SET
                memberUUID = memberUUID
                <cfif structKeyExists( arguments.memberKeys, "fghfghfgh" ) and not arguments.doSomething>
                    ,fghfghfgh = <cfqueryparam cfsqltype="cf_sql_varchar" value="#left(htmlEditFormat( arguments.memberKeys.fghfghfgh ),30)#">
                </cfif>
                <cfif structKeyExists( arguments.memberKeys, "fghfghfghfgfg" )>
                    ,fghfghfghfgfg = getDate()
                </cfif>
                ...

The outcome I get is:

        <cfquery name="fghfgf" datasource="#dsn#">
            UPDATE fghfghfg
            SET
                memberUUID = memberUUID
                <cfif structKeyExists( arguments.memberKeys, "fghfghfgh" ) and not arguments.doSomething>
                    ,fghfghfgh = <cfqueryparam
            cfsqltype="cf_sql_varchar"
            value="#left(
                htmlEditFormat( arguments.memberKeys.fghfghfgh ),
                30
            )#"
        >
                </cfif>
                <cfif structKeyExists( arguments.memberKeys, "fghfghfghfgfg" )>
                    ,fghfghfghfgfg = getDate()
                </cfif>

It seems it has an issue with the correct indentation of the nested cfqueryparam tag.

What the outcome probably should be from my point of view is:

        <cfquery name="fghfgf" datasource="#dsn#">
            UPDATE fghfghfg
            SET
                memberUUID = memberUUID
                <cfif structKeyExists( arguments.memberKeys, "fghfghfgh" ) and not arguments.doSomething>
                    ,fghfghfgh = <cfqueryparam
                        cfsqltype="cf_sql_varchar"
                        value="#left(
                            htmlEditFormat( arguments.memberKeys.fghfghfgh ),
                            30
                        )#"
                    >
                </cfif>
                <cfif structKeyExists( arguments.memberKeys, "fghfghfghfgfg" )>
                    ,fghfghfghfgfg = getDate()
                </cfif>

TheRealAgentK avatar Oct 01 '20 00:10 TheRealAgentK

Thanks for the report. This is a tricky situation (as things stand now). Inside of cfquery tags, cformat endeavors to preserve the white space formatting that is already in place. It does not up the indent level inside the body of tags within the cfquery, but preserves what you already have in place. So when it decides to render the cfqueryparam over multiple lines, it just uses an indent level of "cfquery + 1" to indent the attributes of the param. I don't currently have a good way to compute the "actual" indent level of tags inside of the cfquery (i.e. how nested they are), while keeping the rendered indent level unchanged. The only nested tag tracking done is done by the indent level, and that does not change inside of a cfquery tag (currently).

I will keep thinking about possible solutions for this.

jcberquist avatar Oct 02 '20 18:10 jcberquist

Ah ok, I understand.

For now I'm working around it using the ignore statements to leave the formatting as it is in my first sample, so it's not terrible at the moment :)

TheRealAgentK avatar Oct 03 '20 03:10 TheRealAgentK