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

StringBuilder.appendQuotedIfNotNull is used incorrectly. #2728

Open
teo-tsirpanis opened this issue Jan 10, 2023 · 4 comments
Open

StringBuilder.appendQuotedIfNotNull is used incorrectly. #2728

teo-tsirpanis opened this issue Jan 10, 2023 · 4 comments

Comments

@teo-tsirpanis
Copy link
Contributor

In

let inline appendQuotedIfNotNull (value: Object) s (builder: StringBuilder) =
if (value = null) then
builder
else
(match value with
| :? String as sv -> builder.Append(sprintf "%s\"%s\" " s sv)
| _ -> builder.Append(sprintf "%s\"%A\" " s value))
we are appending nothing if value is null, but if it isn't we append both s and value.

This doesn't work well with code like

let internal quoteString str =
StringBuilder()
|> StringBuilder.appendQuotedIfNotNull Some str
|> StringBuilder.toText

value is Some, which is a function, and displaying does not make any sense, leading to errors like https://ci.appveyor.com/project/teo-tsirpanis/farkle/builds/45896483/job/9et0xrw72ibtg3ar#L6292.

teo-tsirpanis added a commit to teo-tsirpanis/Farkle that referenced this issue Jan 10, 2023
We can't upgrade until fsprojects/FAKE#2728 gets fixed.
@yazeedobaid
Copy link
Collaborator

@teo-tsirpanis thanks for reporting, can you send a PR?

@teo-tsirpanis
Copy link
Contributor Author

I can't understand what the correct code would be. I would have already sent it if I could. 😅

@teo-tsirpanis
Copy link
Contributor Author

@yazeedobaid I want to fix the bug, can you help me understand it? What should appendQuotedIfNotNull do?

@yazeedobaid
Copy link
Collaborator

@teo-tsirpanis the function should escape quotations in the passed string if it has any. It is being discussed in this PR #2739

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

No branches or pull requests

2 participants