Skip to content

StringBuilder.appendQuotedIfNotNull is used incorrectly. #2728

Open

Description

@teo-tsirpanis

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.

Activity

  1. added a commit that references this issue on Jan 10, 2023
  2. yazeedobaid commented on Jan 11, 2023

    @yazeedobaid
    Collaborator

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

  3. teo-tsirpanis commented on Jan 11, 2023

    @teo-tsirpanis
    ContributorAuthor

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

  4. teo-tsirpanis commented on Feb 28, 2023

    @teo-tsirpanis
    ContributorAuthor

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

  5. yazeedobaid commented on Mar 16, 2023

    @yazeedobaid
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions