Skip to content

[BUG] Encode Selection as M Text Value is missing escapes on complex values #167

@ninmonkey

Description

@ninmonkey

Expected behavior

I'm expecting the selected value will escaped quotes, converting it to a raw string.
I thought it would simplify adding the Code part of function's metadata ( Documentation.Examples )

For example this

let
    x  = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcszNr8hMzszJycxT0EgsVjBUcFTQVIrVwSbjjFNGAY8uhEwBskRxfkppLhYpoFkwWaBkLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Raw Name" = _t])
in 
    x

Expected Output

let
    x  = "Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(""i45WcszNr8hMzszJycxT0EgsVjBUcFTQVIrVwSbjjFNGAY8uhEwBskRxfkppLhYpoFkwWaBkLAA="", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#""Raw Name"" = _t])"
in 
    x

Actual behavior

let
    x  = 
Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(""i45WcszNr8hMzszJycxT0EgsVjBUcFTQVIrVwSbjjFNGAY8uhEwBskRxfkppLhYpoFkwWaBkLAA="", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#(#)""Raw Name"" = _t])
in 
    x

To Reproduce

VsCode.PowerQuery.-.text.to.M.expression.-.2022-09.-.export.1.mp4

Environment

Name Version
Extension PowerQuery.vscode-powerquery@0.1.45
Code code: 1.71.2, 74b1f979648cc44d385a2286793c226e611f59e7, x64
Pwsh>
    code.cmd --show-versions --list-extensions | sls 'powerquery'
    code.cmd --version | Join-String -sep ', ' -op 'vscode: '

Solution?

A naive replace appears to be working, at least for this sample

  1. Replace " with ""
  2. Surround that with ""
Pwsh> $Content -replace '"', '""'
    | Join-String -op '"' -os '"'

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions