Skip to content
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

Fixes #1090 #1108

Merged
merged 1 commit into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"presentation": {
"reveal": "always",
"panel": "new"
}
},
"problemMatcher": []
},
{
"label": "Build Release",
Expand Down
2 changes: 2 additions & 0 deletions src/UniversalDashboard.UITest/Assets/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
using module Microsoft.PowerShell.Utility
'Hello' | ConvertTo-Json
18 changes: 18 additions & 0 deletions src/UniversalDashboard.UITest/Integration/Api.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ Import-Module $ModulePath -Force
Get-UDRestApi | Stop-UDRestApi
Get-UDDashboard | Stop-UDDashboard
Describe "Api" {

Context "script block with requires" {
$Server = Start-UDRestApi -Port 10001 -Endpoint @(

$ScriptBlock = [ScriptBlock]::Create((Get-Content (Join-Path $PSScriptRoot "../Assets/requires.txt") -Raw))

New-UDEndpoint -Url "/scriptblock" -Method "GET" -Endpoint $ScriptBlock
)

It "not throw an error" {
(Invoke-RestMethod http://localhost:10001/api/scriptblock?hello=test) | Should be "Hello"
}

Stop-UDRestApi $Server
}

Wait-Debugger

Context "Special Characters" {
$Server = Start-UDRestApi -Port 10001 -Endpoint @(
New-UDEndpoint -Url "/recherches" -Method "GET" -Endpoint {
Expand Down
11 changes: 10 additions & 1 deletion src/UniversalDashboard/Execution/ExecutionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public object ExecuteEndpoint(ExecutionContext context, Endpoint endpoint)
}

var paramBlockBuilder = new StringBuilder();

if (scriptBlockAst.UsingStatements != null)
{
foreach(var usingStatement in scriptBlockAst.UsingStatements)
{
paramBlockBuilder.AppendLine(usingStatement.ToString());
}
}

paramBlockBuilder.Append("param(");

foreach (var parameter in context.Parameters)
Expand All @@ -84,7 +93,7 @@ public object ExecuteEndpoint(ExecutionContext context, Endpoint endpoint)
paramBlockBuilder.Append(")");
paramBlockBuilder.AppendLine();

script = paramBlockBuilder.ToString() + script;
script = paramBlockBuilder.ToString() + scriptBlockAst.EndBlock.ToString();
}

Collection<PSObject> output;
Expand Down