Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文字列リテラルでエスケープできるようにする #1

Merged
merged 2 commits into from
Jun 17, 2021

Conversation

tuchida
Copy link
Collaborator

@tuchida tuchida commented Jun 17, 2021

ref. https://github.com/smartoperation/saasx/issues/3675, osteele#45

まずLiquidはShopifyのものが本家みたいなんだけど、その仕様では文字列リテラルのエスケープをしないと書いてある
https://shopify.github.io/liquid/basics/types/#string

Liquid does not convert escape sequences into special characters.

このproposalでは``内ではエスケープできるようにするという仕様が提案されている
Shopify/liquid#1174 (comment)

本PRでは、クライアント側の都合によりJSONと互換性があると楽なのと、strconv.Unquoteがよさそうだったので、""のみエスケープする、という実装にした

@tuchida tuchida requested a review from anoChick June 17, 2021 05:07
string = '"' (any - '"')* '"' | "'" (any - "'")* "'" ; # TODO escapes

dqchar = [^"\\] | ( '\\' any );
string = '"' . dqchar* . '"' | "'" (any - "'")* "'" ;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if lex.data[lex.ts] == '\'' {
s = string(lex.data[lex.ts+1:lex.te-1])
} else {
unquotedStr, err := strconv.Unquote(string(lex.data[lex.ts:lex.te]))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://golang.org/pkg/strconv/#Unquote
strconv.Unquoteはシングルクォートを(文字列ではなく)文字として認識するため、2文字以上あるとエラーになる
ちなみにstrconv.Unquoteは``も有効な文字列として認識するのだけど、字句解析では許容していないので、ここにこないはず

@tuchida tuchida merged commit 89d84ba into smartoperation:master Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants