Skip to content

fix(snippetz): escape strings in C# HttpClient code examples - #10503

Merged
hanspagel merged 2 commits into
scalar:mainfrom
charan-rathore:fix/snippetz-csharp-httpclient-escape
Oct 6, 2026
Merged

hanspagel merged 2 commits into
scalar:mainfrom
charan-rathore:fix/snippetz-csharp-httpclient-escape

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Problem

The C# HttpClient code example writes some values into C# string literals without escaping them, so the copied code does not compile or sends different data:

  • A URL, header name or value, cookie, Authorization scheme or token, or form field that contains a double quote or backslash breaks the string literal.
  • Octet-stream bodies escaped quotes but not backslashes or line breaks, so a body with \ or a new line was written wrongly.
  • The same goes for Accept values and multipart content types.

Solution

Use the existing escapeCSharpString helper for these values, and make it escape carriage returns and new lines too. JSON and text bodies still use the raw string literal, so their output is unchanged.

I added tests for a URL, headers, cookie and form fields with quotes and backslashes, and for an octet-stream body with a backslash and a line break. Both fail without the fix.

Checklist

  • I explained why the change is needed.
  • I added a changeset.
  • I added tests.
  • I updated the documentation. (not needed, no docs describe this)

@changeset-bot

changeset-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9ac4f82

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@scalar/snippetz Patch
@scalar/java-integration Patch
@scalar/api-client Patch
@scalar/api-reference Patch
@scalar/blocks Patch
@scalar/workspace-store Patch
@scalar/nuxt Patch
@scalar/agent-chat Patch
@scalar/api-client-react Patch
scalar-app Patch
@scalarapi/docker-api-reference Patch
@scalar/aspire Patch
@scalar/aspnetcore Patch
@scalar/aws-lambda Patch
@scalar/azure-functions Patch
@scalar/fastify-api-reference Patch
scalar_api_reference Patch
@scalar/api-reference-react Patch
@scalar/server-side-rendering Patch
@scalar/mock-server Patch
@scalar/oas-utils Patch
@scalar/openapi-to-markdown Patch
@scalar/pre-post-request-scripts Patch
@scalar/sidebar Patch
@scalar/mock-server-docker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hanspagel
hanspagel force-pushed the fix/snippetz-csharp-httpclient-escape branch from 9eddbcc to 9ac4f82 Compare October 6, 2026 09:31
@hanspagel
hanspagel temporarily deployed to production-netlify October 6, 2026 09:34 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify October 6, 2026 09:34 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify October 6, 2026 09:34 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify October 6, 2026 09:34 — with GitHub Actions Inactive
@hanspagel
hanspagel temporarily deployed to production-netlify October 6, 2026 09:34 — with GitHub Actions Inactive
@hanspagel
hanspagel merged commit a27ab16 into scalar:main Oct 6, 2026
32 checks passed
@charan-rathore
charan-rathore deleted the fix/snippetz-csharp-httpclient-escape branch October 6, 2026 09:46
@scalar-release-bot scalar-release-bot Bot mentioned this pull request Oct 6, 2026

This branch was previously deployed

1 inactive deployment
production-netlify — 9ac4f821 Deployed Oct 6, 2026 by hanspagel via test-e2e-api-reference #3202
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.

2 participants