Skip to content

🩹 [Patch]: Add Base64Url string conversion functions#11

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-10
Draft

🩹 [Patch]: Add Base64Url string conversion functions#11
Copilot wants to merge 2 commits intomainfrom
copilot/fix-10

Conversation

Copy link
Contributor

Copilot AI commented Sep 13, 2025

This PR adds comprehensive Base64Url string conversion functionality to the module, providing URL-safe variants of the existing Base64 functions.

What's Added

New Functions

ConvertTo-Base64Url - Converts strings to base64url encoding

  • Replaces + with - and / with _ for URL safety
  • Removes padding = characters
  • Supports pipeline input and multiple encoding options
  • Includes alias ConvertTo-Base64UrlString

ConvertFrom-Base64Url - Decodes base64url strings

  • Handles URL-safe characters (- and _)
  • Automatically adds padding when needed for proper decoding
  • Validates input using Test-Base64Url function
  • Includes alias ConvertFrom-Base64UrlString

Test-Base64Url - Validates base64url strings

  • Checks for valid character set (A-Z, a-z, 0-9, -, _)
  • Rejects standard base64 characters (+, /, =)
  • Returns boolean validation result

Usage Examples

# Convert to Base64Url (URL-safe, no padding)
"Hello World" | ConvertTo-Base64Url
# Output: SGVsbG8gV29ybGQ

# Convert from Base64Url
"SGVsbG8gV29ybGQ" | ConvertFrom-Base64Url  
# Output: Hello World

# Validate Base64Url strings
"SGVsbG8gV29ybGQ" | Test-Base64Url        # True (valid)
"Invalid+String/=" | Test-Base64Url       # False (contains +, /, =)

# Round-trip conversion maintains data integrity
$original = "Test string with special chars: +/?="
$encoded = $original | ConvertTo-Base64Url
$decoded = $encoded | ConvertFrom-Base64Url
$original -eq $decoded  # True

Key Features

  • URL-Safe: Uses - and _ instead of + and /
  • No Padding: Removes = padding characters for cleaner URLs
  • Pipeline Support: Full ValueFromPipeline compatibility
  • Multiple Encodings: Supports UTF8, ASCII, Unicode, etc.
  • Input Validation: Robust validation with helpful error messages
  • Consistent API: Follows the same patterns as existing Base64 functions

Testing

Added 21 comprehensive test cases covering:

  • Basic conversion functionality
  • Pipeline input handling
  • Array processing
  • File content processing
  • URL-safe character validation
  • Round-trip conversion integrity
  • Error handling for invalid inputs

All 35 tests pass (14 existing + 21 new).

Fixes #10.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Sep 13, 2025

Marius Storhaug (@MariusStorhaug) 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

…Test-Base64Url

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copilot AI changed the title [WIP] 🩹 [Patch]: Add functions to convert to and from Base64Strings 🩹 [Patch]: Add Base64Url string conversion functions Sep 13, 2025
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.

🩹 [Patch]: Add functions to convert to and from Base64Strings

2 participants