Skip to content

Use PowerShell here-strings for shareable queries#132

Merged
MathiasVDA merged 5 commits intomainfrom
copilot/update-share-to-powershell-function
Feb 12, 2026
Merged

Use PowerShell here-strings for shareable queries#132
MathiasVDA merged 5 commits intomainfrom
copilot/update-share-to-powershell-function

Conversation

Copy link

Copilot AI commented Feb 12, 2026

PowerShell Share Feature Improvements

  • Update getAsPowerShellString in sparql.ts to use multi-line string format with $query = @"..."@
  • Change the Body parameter to use the unencoded query instead of URL-encoded form
  • Update the output file name from result.${ext} to sparql-generated.${ext}
  • Add or update tests for the new PowerShell format
  • Test the changes manually
  • Run code review and security checks
  • Fix variable expansion issue in Body parameter

Changes Made

  1. Multi-line here-string format: The PowerShell command now uses $query = @"..."@ syntax for the query parameter, making it much easier to edit before execution
  2. Unencoded query text: The query is no longer URL-encoded in the Body parameter, allowing direct editing of ORDER BY, LIMIT, and other SPARQL clauses
  3. Better output filename: Changed from result.${ext} to sparql-generated.${ext} to make it clearer what the file contains
  4. Support for both query and update: The implementation handles both SPARQL queries ($query) and updates ($update)
  5. Fixed variable expansion: The Body parameter now correctly references $query without escaping, allowing PowerShell to expand the variable

Example Output

After fix:

$query = @"
SELECT * WHERE { ?s ?p ?o } ORDER BY ?s LIMIT 10
"@

$params = @{
    Uri = "https://dbpedia.org/sparql"
    Method = "Post"
    Headers = @{
        "Accept" = "application/sparql-results+json,*/*;q=0.9"
    }
    ContentType = "application/x-www-form-urlencoded"
    Body = "query=$query"
    OutFile = "sparql-generated.json"
}

Invoke-WebRequest @params

Test Results

PowerShell Share Test Results - Fixed

All validation checks passed:

  • ✓ Contains $query or $update variable
  • ✓ Contains closing @"
  • ✓ Contains actual query text (not encoded)
  • ✓ Contains ORDER BY clause
  • ✓ Contains Body with variable reference (not escaped)
  • ✓ Contains sparql-generated output file
  • ✓ Does NOT contain URL-encoded query
  • ✓ Does NOT contain encoded equals

Benefits

  • Easier to edit: Users can now easily modify the query before execution without dealing with URL encoding
  • Better for solution sequence modifiers: Common use case of removing or changing ORDER BY, LIMIT, OFFSET clauses is now straightforward
  • Clearer output: The sparql-generated.json filename better indicates what the file contains
  • Proper PowerShell variable expansion: The $query variable is correctly expanded by PowerShell

Security Summary

✓ CodeQL analysis completed with no security vulnerabilities found

Original prompt

This section details on the original issue you should resolve

<issue_title>Share to PowerShell to use non-encoded query</issue_title>
<issue_description>Currently, the share to PowerShell function is given as a parameter of Body in encoded form.
However, it would be more convenient to use

$query = @"
#query string
"@

so that it is easier to edit before executing. A common case is removing or changing the solution sequence modifiers.

Also, I would suggest a default output file sparql-generated.ttl so that it more clearly says what it is.
</issue_description>

<agent_instructions>This is about the share feature in the yasqe package.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@MathiasVDA Good points, I'll make the change

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 12, 2026 14:30
Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
…e logic

Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
Copilot AI changed the title [WIP] Update share to PowerShell for non-encoded query Use PowerShell here-strings for shareable queries Feb 12, 2026
Copilot AI requested a review from MathiasVDA February 12, 2026 14:35
@MathiasVDA
Copy link
Collaborator

@copilot , this doesn't look good. A simple test results in this powershell share output:

$params = @{
Uri = "https://dbpedia.org/sparql"
Method = "Post"
Headers = @{
"Accept" = "application/sparql-results+json,/;q=0.9"
}
ContentType = "application/x-www-form-urlencoded"
Body = "query=`$query"
OutFile = "sparql-generated.json"
}

The $query variable is not c

…meter

Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 12, 2026

@copilot , this doesn't look good. A simple test results in this powershell share output:

$params = @{
...

Fixed in commit afd58a1. The issue was that the escapePowerShellString function was escaping the $ character in the Body parameter, turning $query into `$query which prevented PowerShell from expanding the variable.

The fix constructs the Body expression without escaping the variable reference, so now it outputs:

Body = "query=$query"

Fixed output

@MathiasVDA MathiasVDA marked this pull request as ready for review February 12, 2026 17:25
@MathiasVDA MathiasVDA merged commit d31612a into main Feb 12, 2026
2 checks passed
@MathiasVDA MathiasVDA deleted the copilot/update-share-to-powershell-function branch February 12, 2026 17:27
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.

Share to PowerShell to use non-encoded query

2 participants