(t *testing.T)
| 311 | } |
| 312 | |
| 313 | func TestEscapeBareShellDollarSigns(t *testing.T) { |
| 314 | tests := []struct { |
| 315 | name string |
| 316 | input string |
| 317 | expected string |
| 318 | }{ |
| 319 | { |
| 320 | name: "empty string", |
| 321 | input: "", |
| 322 | expected: "", |
| 323 | }, |
| 324 | { |
| 325 | name: "no dollar signs", |
| 326 | input: "no dollars here", |
| 327 | expected: "no dollars here", |
| 328 | }, |
| 329 | { |
| 330 | name: "bare dollar followed by identifier", |
| 331 | input: "$schema", |
| 332 | expected: `\$schema`, |
| 333 | }, |
| 334 | { |
| 335 | name: "dollar sign at end of string", |
| 336 | input: "trailing$", |
| 337 | expected: `trailing\$`, |
| 338 | }, |
| 339 | { |
| 340 | name: "GitHub Actions expression is preserved", |
| 341 | input: "${{ env.DOMAINS }}", |
| 342 | expected: "${{ env.DOMAINS }}", |
| 343 | }, |
| 344 | { |
| 345 | name: "multiple GitHub Actions expressions are preserved", |
| 346 | input: "${{ env.A }},${{ env.B }}", |
| 347 | expected: "${{ env.A }},${{ env.B }}", |
| 348 | }, |
| 349 | { |
| 350 | name: "bare dollar mixed with GitHub Actions expression", |
| 351 | input: `$schema and ${{ env.X }}`, |
| 352 | expected: `\$schema and ${{ env.X }}`, |
| 353 | }, |
| 354 | { |
| 355 | name: "JSON $schema key alongside expression", |
| 356 | input: `{"$schema":"https://example.com","allowDomains":["${{ env.DOMAINS }}"]}`, |
| 357 | expected: `{"\$schema":"https://example.com","allowDomains":["${{ env.DOMAINS }}"]}`, |
| 358 | }, |
| 359 | { |
| 360 | name: "dollar followed by single open brace is escaped", |
| 361 | input: "${HOME}", |
| 362 | expected: `\${HOME}`, |
| 363 | }, |
| 364 | { |
| 365 | name: "dollar followed by ${{ is preserved", |
| 366 | input: "${{", |
| 367 | expected: "${{", |
| 368 | }, |
| 369 | } |
| 370 |
nothing calls this directly
no test coverage detected