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

json_ParseString handling of new line (\n) #270

Closed
zgrose opened this issue Dec 28, 2016 · 4 comments · May be fixed by #272
Closed

json_ParseString handling of new line (\n) #270

zgrose opened this issue Dec 28, 2016 · 4 comments · May be fixed by #272

Comments

@zgrose
Copy link

zgrose commented Dec 28, 2016

I believe the n case in json_ParseString should be changed to append a vbLf instead of a vbCrLf or there should be an option to override the default behavior (I copied the current code into this issue at the bottom).

I noticed this issue when assigning a value to a TextBox.

My JSON was (simplified): { "Prop" : "Foo \r\nBar" }

In the Immediate window this shows
Foo
Bar

But when I assign that value to a TextBox that is MultiLine=True and EnterKeyBehavior=True

Me.TextBox1.Value = jobject("Prop")

the form shows Foo Bar in the TextBox.

If I change the JSON text to be { "Prop" : "Foo \nBar" } it displays properly.
If I change your code from vbCrLf to vbLf it displays properly.

I believe this is also a "truer" conversion for \n

Current code from 4.1.1

            Case "n"
                json_BufferAppend json_buffer, vbCrLf, json_BufferPosition, json_BufferLength
                json_Index = json_Index + 1
            Case "r"
                json_BufferAppend json_buffer, vbCr, json_BufferPosition, json_BufferLength
                json_Index = json_Index + 1
@Sophist-UK
Copy link
Contributor

I would suggest the following:

            Case "n"
                If VBA.Mid$(json_String, json_Index+1, 2) == "\r" Then
                    json_BufferAppend json_buffer, vbCrLf, json_BufferPosition, json_BufferLength
                    json_Index = json_Index + 3
                Else
                    json_BufferAppend json_buffer, vbLf, json_BufferPosition, json_BufferLength
                    json_Index = json_Index + 1
                End If
            Case "r"
                If VBA.Mid$(json_String, json_Index+1, 2) == "\n" Then
                    json_BufferAppend json_buffer, vbCrLf, json_BufferPosition, json_BufferLength
                    json_Index = json_Index + 3
                Else
                    json_BufferAppend json_buffer, vbCr, json_BufferPosition, json_BufferLength
                    json_Index = json_Index + 1
                End If

@timhall
Copy link
Member

timhall commented Dec 29, 2016

@zgrose Thanks for raising this issue, @Sophist-UK looks good to me, I'll make this change

Sophist-UK added a commit to Sophist-UK/VBA-JSON that referenced this issue Jan 9, 2017
Addresses VBA-tools#41.

Fix as per discussion in VBA-tools/VBA-Web#270
Sophist-UK added a commit to Sophist-UK/VBA-Web that referenced this issue Jan 9, 2017
@timhall
Copy link
Member

timhall commented Aug 11, 2017

(moved to VBA-JSON)

@Sophist-UK
Copy link
Contributor

If the JSON fix was applied and then made it into VBA-WEB from there, then #272 should probably be closed.

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 a pull request may close this issue.

3 participants