Skip to content

[Bug]: Internal HTTP server doesn't return file when filename doesn't have "." in it#8577

Description

@jmarshall-com

Capacitor Version

馃拪 Capacitor Doctor 馃拪

Latest Dependencies:

@capacitor/cli: 8.5.0
@capacitor/core: 8.5.0
@capacitor/android: 8.5.0
@capacitor/ios: 8.5.0

Installed Dependencies:

@capacitor/cli: 8.4.1
@capacitor/core: 8.4.1
@capacitor/android: 8.4.2
@capacitor/ios: 8.4.1

[success] iOS looking great! 馃憣
[success] Android looking great! 馃憣

Other API Details

npm version: 11.18.0
node version: v24.12.0

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

When I fetch() a local data file that is included under webDir, and the filename doesn't have a "." (dot) in it, the fetch() returns the /index.html file instead, every time. As long as the filename has a "." in it, the correct file is returned.

Expected Behavior

A fetch() should get the correct file from under webDir regardless of whether the filename has an extension or not.

Project Reproduction

hoping the bug isolation below precludes the need for a test case....

Additional Information

I'm guessing the bug is in handleLocalRequest() in WebViewLocalServer.java. Line 374 is:

if (isLocalFile(request.getUrl()) || isErrorUrl(request.getUrl())) {

Is this supposed to detect if the URL points to a file under webDir? isLocalFile() just tests for the URL path starting with either capacitorContentStart or capacitorFileStart, which come from constants in Bridge.java, but the request URL doesn't start with either of those. Instead of executing this block, it skips over and passes the test on line 399, which is:

if (path.equals("/") || (!request.getUrl().getLastPathSegment().contains(".") && html5mode)) {

... thus returning /index.html. (I don't know why the .contains(".") test is in there, or what html5mode is.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions