Skip to content

Conversation

@Gijsreyn
Copy link
Contributor

PR Summary

This pull request adds the dataUri and dataUriToString functions, including tests and documentation.

PR Context

Partially addresses #57.

@Gijsreyn Gijsreyn force-pushed the gh-57/main/add-datauri-functions branch from bf06fc1 to aa04b78 Compare January 12, 2026 23:22
Comment on lines 1784 to 1787
@{ expression = "[dataUriToString('data:text/plain;;base64,SGVsbG8=')]" ; expected = 'Hello' }
@{ expression = "[dataUriToString('data::text/plain;base64,SGVsbG8=')]" ; expected = 'Hello' }
@{ expression = "[dataUriToString('data:text/plain;charset=utf-8;charset=utf-8;base64,SGVsbG8=')]" ; expected = 'Hello' }
@{ expression = "[dataUriToString('data:text/plain;foo=bar;base64,SGVsbG8=')]" ; expected = 'Hello' }
Copy link
Member

Choose a reason for hiding this comment

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

The ARM implementation seems more strict in the format validation and I believe these would all be errors

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds two new DSC configuration functions: dataUri() and dataUriToString(). The dataUri() function converts a string to a base64-encoded data URI format, while dataUriToString() performs the inverse operation by decoding a data URI back to its original string.

Changes:

  • Added dataUri() function to convert strings to data URI format with base64 encoding
  • Added dataUriToString() function to decode base64-encoded data URIs back to strings
  • Included comprehensive unit tests and integration tests for both functions
  • Added documentation with examples for both functions

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
lib/dsc-lib/src/functions/mod.rs Registered the new data_uri and data_uri_to_string modules in alphabetical order
lib/dsc-lib/src/functions/data_uri.rs Implemented dataUri() function that encodes strings as base64 data URIs with application/json media type
lib/dsc-lib/src/functions/data_uri_to_string.rs Implemented dataUriToString() function that decodes base64-encoded data URIs to strings with UTF-8 validation
lib/dsc-lib/locales/en-us.toml Added localization strings for function descriptions and error messages
dsc/tests/dsc_functions.tests.ps1 Added comprehensive PowerShell integration tests covering normal operation, error cases, and edge cases
docs/reference/schemas/config/functions/overview.md Added references to the new functions in the string functions section
docs/reference/schemas/config/functions/dataUri.md Added documentation for dataUri() function with examples and parameter descriptions
docs/reference/schemas/config/functions/dataUriToString.md Added documentation for dataUriToString() function with examples and exception details

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

actualState:
output:
originalScript: Write-Host 'Hello, World!'
encodedScript: data:text/plain;charset=utf8;base64,V3JpdGUtSG9zdCAnSGVsbG8sIFdvcmxkISc=
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation example shows the function returning a data URI with text/plain media type, but the actual implementation uses application/json. This should be updated to match the actual output format produced by the function.

Copilot uses AI. Check for mistakes.
## Output

The `dataUri()` function returns a data URI string in the format
`data:text/plain;charset=utf8;base64,<encoded-content>` where `<encoded-content>` is the base64
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The Output section states the function returns a data URI with text/plain media type, but the actual implementation uses application/json. This should be updated to match the actual output format produced by the function.

Suggested change
`data:text/plain;charset=utf8;base64,<encoded-content>` where `<encoded-content>` is the base64
`data:application/json;charset=utf8;base64,<encoded-content>` where `<encoded-content>` is the base64

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +27
The function supports both base64-encoded data URIs (those containing `;base64` in the metadata)
and URL-encoded data URIs. It automatically detects the encoding method and decodes accordingly.
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation claims the function supports URL-encoded data URIs, but the implementation at line 56 explicitly requires base64 encoding and returns an error for non-base64 data URIs. This documentation should be corrected to indicate that only base64-encoded data URIs are supported.

Suggested change
The function supports both base64-encoded data URIs (those containing `;base64` in the metadata)
and URL-encoded data URIs. It automatically detects the encoding method and decodes accordingly.
The function supports only base64-encoded data URIs (those containing `;base64` in the metadata).
Non-base64 or URL-encoded data URIs aren't supported and result in an error.

Copilot uses AI. Check for mistakes.
Comment on lines +180 to +181
must start with `data:` and contain a comma separating the metadata from the encoded data. If the
metadata contains `;base64`, the data is decoded as base64; otherwise, it's decoded as URL-encoded.
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation claims that data will be decoded as URL-encoded if ;base64 is not present in the metadata. However, the implementation at line 56 requires base64 encoding and returns an error for non-base64 data URIs. This should be corrected to reflect that only base64-encoded data URIs are supported.

Suggested change
must start with `data:` and contain a comma separating the metadata from the encoded data. If the
metadata contains `;base64`, the data is decoded as base64; otherwise, it's decoded as URL-encoded.
must start with `data:` and contain a comma separating the metadata from the encoded data. The
metadata must include `;base64`, and the data portion is decoded as base64. Data URIs without
`;base64` metadata are not supported and result in an error.

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +191

<!-- Link reference definitions -->
[01]: https://en.wikipedia.org/wiki/Data_URI_scheme
[02]: base64.md
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The dataUri.md documentation is missing a "Related functions" section that should include links to dataUriToString(), base64(), and base64ToString(), similar to how other related functions like base64ToString.md include this section.

Suggested change
<!-- Link reference definitions -->
[01]: https://en.wikipedia.org/wiki/Data_URI_scheme
[02]: base64.md
## Related functions
- [`dataUriToString()`][03]
- [`base64()`][02]
- [`base64ToString()`][04]
<!-- Link reference definitions -->
[01]: https://en.wikipedia.org/wiki/Data_URI_scheme
[02]: base64.md
[03]: dataUriToString.md
[04]: base64ToString.md

Copilot uses AI. Check for mistakes.
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: data:text/plain;charset=utf8;base64,eyJzZXR0aW5nIjoidmFsdWUiLCJlbmFibGVkIjp0cnVlfQ==
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation example shows the function returning a data URI with text/plain media type, but the actual implementation uses application/json. This should be updated to match the actual output format produced by the function.

Copilot uses AI. Check for mistakes.
actualState:
output:
base64Only: SGVsbG8=
fullDataUri: data:text/plain;charset=utf8;base64,SGVsbG8=
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation example shows the function returning a data URI with text/plain media type, but the actual implementation uses application/json. This should be updated to match the actual output format produced by the function.

Copilot uses AI. Check for mistakes.
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: data:text/plain;charset=utf8;base64,bGluZTEKbGluZTIKbGluZTM=
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation example shows the function returning a data URI with text/plain media type, but the actual implementation uses application/json. This should be updated to match the actual output format produced by the function.

Copilot uses AI. Check for mistakes.
actualState:
output:
base64Only: SGVsbG8=
fullDataUri: data:text/plain;charset=utf8;base64,SGVsbG8=
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation example shows the output includes charset=utf8, but the implementation does not include a charset parameter in the data URI. The documentation should be updated to reflect the actual output format without the charset parameter.

Copilot uses AI. Check for mistakes.
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: data:text/plain;charset=utf8;base64,bGluZTEKbGluZTIKbGluZTM=
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The documentation example shows the output includes charset=utf8, but the implementation does not include a charset parameter in the data URI. The documentation should be updated to reflect the actual output format without the charset parameter.

Copilot uses AI. Check for mistakes.
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