-
Notifications
You must be signed in to change notification settings - Fork 55
Add dataUri and dataUriToString functions
#1332
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
base: main
Are you sure you want to change the base?
Add dataUri and dataUriToString functions
#1332
Conversation
bf06fc1 to
aa04b78
Compare
dsc/tests/dsc_functions.tests.ps1
Outdated
| @{ 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' } |
There was a problem hiding this comment.
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
There was a problem hiding this 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= |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| ## 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 |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| `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 |
| 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. |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| 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. |
| 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. |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| 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. |
|
|
||
| <!-- Link reference definitions --> | ||
| [01]: https://en.wikipedia.org/wiki/Data_URI_scheme | ||
| [02]: base64.md |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| <!-- 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 |
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: data:text/plain;charset=utf8;base64,eyJzZXR0aW5nIjoidmFsdWUiLCJlbmFibGVkIjp0cnVlfQ== |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| actualState: | ||
| output: | ||
| base64Only: SGVsbG8= | ||
| fullDataUri: data:text/plain;charset=utf8;base64,SGVsbG8= |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: data:text/plain;charset=utf8;base64,bGluZTEKbGluZTIKbGluZTM= |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| actualState: | ||
| output: | ||
| base64Only: SGVsbG8= | ||
| fullDataUri: data:text/plain;charset=utf8;base64,SGVsbG8= |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: data:text/plain;charset=utf8;base64,bGluZTEKbGluZTIKbGluZTM= |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
PR Summary
This pull request adds the
dataUrianddataUriToStringfunctions, including tests and documentation.PR Context
Partially addresses #57.