Skip to content

Fix: Index out of bounds panic in SwaggerUIHandler for files without extension#3217

Merged
Umang01-hash merged 6 commits into
gofr-dev:developmentfrom
NitinKumar004:fix/swagger-ui-index-out-of-bounds
Apr 29, 2026
Merged

Fix: Index out of bounds panic in SwaggerUIHandler for files without extension#3217
Umang01-hash merged 6 commits into
gofr-dev:developmentfrom
NitinKumar004:fix/swagger-ui-index-out-of-bounds

Conversation

@NitinKumar004
Copy link
Copy Markdown
Contributor

@NitinKumar004 NitinKumar004 commented Mar 27, 2026

Summary

  • Replaced strings.Split + direct index access with filepath.Ext to safely extract the file extension.
  • Returns a defined error (errMissingFileExtension) when the filename has no extension, instead of panicking with index out of bounds.
  • Added unit test for the no-extension scenario.

Fixes #3214

Test plan

  • Added TestSwaggerUIHandler_NoFileExtension unit test
  • Existing swagger tests still pass
  • Linter passes with 0 issues

…without extension

Validate file extension using filepath.Ext before accessing it.
Previously, splitting on "." and accessing index [1] would panic
for filenames without a dot.

Fixes gofr-dev#3214
@NitinKumar004 NitinKumar004 force-pushed the fix/swagger-ui-index-out-of-bounds branch from 21f8cfb to f8508c4 Compare March 27, 2026 12:04
Comment thread pkg/gofr/swagger.go Outdated
NitinKumar004 and others added 2 commits April 12, 2026 00:32
…IHandler

Replace plain errors.New() with gofrHTTP.ErrorEntityNotFound so the
framework correctly maps it to 404 Not Found instead of 500 Internal
Server Error. A missing file extension is a client error, not a server error.
@Umang01-hash Umang01-hash merged commit ab62169 into gofr-dev:development Apr 29, 2026
16 checks passed
Umang01-hash added a commit that referenced this pull request Apr 29, 2026
* chore(deps): consolidate minor dependency updates (2026-04-28) (#3365)

Root module:
- github.com/vektah/gqlparser/v2: 2.5.32 → 2.5.33
- modernc.org/sqlite: 1.49.1 → 1.50.0
- github.com/segmentio/kafka-go: 0.4.50 → 0.4.51

Submodules:
- pkg/gofr/datasource/elasticsearch: go-elasticsearch/v8 8.19.4 → 8.19.5
- pkg/gofr/datasource/couchbase: gocb/v2 2.12.1 → 2.12.2
- gofr.dev 1.56.1 → 1.56.3 in 11 sub-modules
  (pubsub/sqs, pubsub/nats, pubsub/eventhub, file/sftp, file/s3,
   file/gcs, file/ftp, file/azure, oracle, dbresolver,
   examples/using-add-filestore)

GitHub Actions:
- crate-ci/typos: 1.45.1 → 1.45.2

Closes: #3364, #3363, #3362, #3361, #3360, #3359, #3358, #3357, #3356,
        #3355, #3354, #3353, #3352, #3351, #3350, #3349, #3348

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Fix: Index out of bounds panic in SwaggerUIHandler for files without extension (#3217)

* fix(kafka): reconnect stale admin conn instead of failing forever (#3347)

* update release version to v1.56.4

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Nitin Kumar Patel <nitin.kumar@zop.dev>
Co-authored-by: Aryan Mehrotra <aryan.mehrotra@gofr.dev>
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.

Fix: Index out of bounds panic in SwaggerUIHandler for files without extension

3 participants