Skip to content

Add Uri.TryGetFileName() extension#77

Merged
Tyrrrz merged 3 commits intoprimefrom
copilot/add-uri-trygetfilename-extension
Apr 19, 2026
Merged

Add Uri.TryGetFileName() extension#77
Tyrrrz merged 3 commits intoprimefrom
copilot/add-uri-trygetfilename-extension

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

Adds a TryGetFileName() instance extension on Uri that extracts the file name from the last path segment, returning null when there is none.

Changes

  • UriExtensions.cs — new TryGetFileName() method in the extension(Uri uri) block; uses direct segment indexing (no LINQ), URL-decodes the result via Uri.UnescapeDataString
  • UriExtensionsTests.cs — covers file name extraction, percent-encoded names, and no-file-name cases

Example

new Uri("https://example.com/files/my%20file.pdf").TryGetFileName(); // "my file.pdf"
new Uri("https://example.com/files/report.csv?v=2").TryGetFileName(); // "report.csv"
new Uri("https://example.com/").TryGetFileName();                     // null

@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 19, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 19, 2026 18:38
Copilot AI review requested due to automatic review settings April 19, 2026 18:38
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.76%. Comparing base (6726493) to head (302eb08).
⚠️ Report is 5 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #77      +/-   ##
==========================================
- Coverage   93.99%   93.76%   -0.24%     
==========================================
  Files         132      132              
  Lines        2616     2678      +62     
  Branches      205      214       +9     
==========================================
+ Hits         2459     2511      +52     
- Misses        113      123      +10     
  Partials       44       44              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants