Skip to content

Comments

Fix URL encoding in content accessor by replacing quote_plus with quote for file URLs#2542

Merged
FredLL-Avaiga merged 5 commits intoAvaiga:developfrom
pranshugupta01:bug/#2523-file-download-with-spaces
Apr 8, 2025
Merged

Fix URL encoding in content accessor by replacing quote_plus with quote for file URLs#2542
FredLL-Avaiga merged 5 commits intoAvaiga:developfrom
pranshugupta01:bug/#2523-file-download-with-spaces

Conversation

@pranshugupta01
Copy link
Contributor

@pranshugupta01 pranshugupta01 commented Apr 5, 2025

What type of PR is this? (Check all that apply)

  • 🛠 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • ⚡ Optimization
  • 📝 Documentation Update

Description

This PR fixes an issue with the file_download control when file names contain spaces. Previously, spaces in filenames were encoded as + characters (using urllib.parse.quote_plus), which caused browsers to fail to locate the files. This PR changes the URL encoding to use urllib.parse.quote instead, which properly encodes spaces as %20 in URLs, allowing files with spaces in their names to be downloaded correctly.

Related Tickets & Documents

How to reproduce the issue

  1. Create two text files in the same directory: sample_file.txt and sample file.txt (with a space)
  2. Create a Taipy app with:
 import taipy.gui.builder as tgb
   from taipy import Gui

   with tgb.Page() as test_page:
       tgb.text("# Test Download button", mode="md")
       tgb.file_download(
           content="sample file.txt",  # Use file with space in name
           label="Download File",
       )

   if __name__ == "__main__":
       gui = Gui(page=test_page)
       gui.run(
           title="Test download",
           use_reloader=True,
       )
  1. Run the app and click the download button
  2. Before the fix: A .htm file is downloaded with a 404 error message
  3. After the fix: The text file is properly downloaded

Backporting

This change should be backported to:

  • 3.0
  • 3.1
  • 4.0
  • develop

Checklist

We encourage keeping the code coverage percentage at 80% or above.

  • ✅ This solution meets the acceptance criteria of the related issue.
  • 📝 The related issue checklist is completed.
  • 🧪 This PR includes unit tests for the developed code.
    If not, explain why:
  • 🔄 End-to-End tests have been added or updated.
    If not, explain why:
  • 📚 The documentation has been updated, or a dedicated issue has been created.
    If not, explain why:
  • 📌 The release notes have been updated.
    If not, explain why:

@FlorianJacta FlorianJacta added 🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon labels Apr 7, 2025
Copy link
Member

@FredLL-Avaiga FredLL-Avaiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test ?

This commit introduces a new test case to verify the functionality of file downloads when the file path contains spaces. The test creates a temporary file, sets the content variable in the GUI, and checks the generated markdown string against expected output, ensuring proper URL encoding for spaces.
@pranshugupta01
Copy link
Contributor Author

Hey @FredLL-Avaiga i have added test , please verify

pranshugupta01 and others added 3 commits April 7, 2025 23:22
… path with spaces

This commit modifies the expected output in the test for file downloads to ensure the correct URL is generated when the file path contains spaces. The change updates the defaultContent attribute to include the proper path format.
…m-pranshugupta01:pranshugupta01/taipy into bug/Avaiga#2523-file-download-with-spaces
Copy link
Member

@FredLL-Avaiga FredLL-Avaiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, tx a lot @pranshugupta01

@FredLL-Avaiga FredLL-Avaiga merged commit 0336c92 into Avaiga:develop Apr 8, 2025
126 checks passed
@pranshugupta01 pranshugupta01 deleted the bug/#2523-file-download-with-spaces branch April 8, 2025 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 BUG] Problem with file_download when file name has spaces

3 participants