Skip to content

How can pongo2 does not escape chars which except TokenSymbols? #336

@mengying1995

Description

@mengying1995
func main() {
	sfsLoader, err := pongo2.NewSandboxedFilesystemLoader(".")
	tplset := pongo2.NewSet("name", sfsLoader)
	tpl, tplErr := tplset.FromFile("create-table.sql.tpl")
	out, outErr := tpl.Execute(pongo2.Context{
		"table_settings": "SETTINGS merge_with_ttl_timeout = 86400, storage_policy = 's3'",
	})
	return out
}

create-table.sql.tpl:

CREATE TABLE IF NOT EXISTS db.table
(
    `name` String,
    `type` String,
    `help` String,
    `labels` Map(String, String) DEFAULT map(),
    `value` Float64,
    `timestamp` Int64
)
ENGINE = MergeTree
PARTITION BY toDate(fromUnixTimestamp64Milli(`timestamp`, 'Asia/Shanghai'))
PRIMARY KEY (`timestamp`, `name`)
ORDER BY (`timestamp`, `name`, `labels`)
-- SETTINGS
{% if (table_settings | default : "") == "" %}
SETTINGS merge_with_ttl_timeout = 86400
{% else %}
{{ table_settings }}
{% endif %}
;

out is:

...Omit
...Omit
-- SETTINGS
SETTINGS merge_with_ttl_timeout = 86400, storage_policy = \u0026#39;s3\u0026#39;
;

Why ' is escaped to \u0026#39; ? How can I avoid this?
Because SQL can not parse \u successfully and can not use ; again and again.

Thank you very much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions