element-android icon indicating copy to clipboard operation
element-android copied to clipboard

#6449 Extended file name support to include characters from multiple languages, including Cyrillic and Han scripts

Open christianrowlands opened this issue 1 year ago • 2 comments

Type of change

  • [ ] Feature
  • [X] Bugfix
  • [ ] Technical
  • [ ] Other :

Content

I fixed an issue when sharing files that had non-Latin characters would have the file name replaced with underscores. For example, here is a screenshot that shows up when "forwarding" a file that was send in Element Android.

image

Motivation and context

Here is a link to the issue: https://github.com/element-hq/element-android/issues/6449

Worthy of note is that I thought about a couple different approaches to fixing this problem. My first regex approach was to use the existing "inclusion" approach, and add Cyrillic and Han scripts. However, after realizing that it could get messy to add support for all the different scripts, I switched to an "exclusion" approach where I remove any known invalid characters.

For reference, here was the first approach

.replace("[^\\p{sc=Cyrillic}\\p{sc=Han}a-z A-Z0-9\\\\.\\-]".toRegex(), "_")

And version 2

.replace("[\\\\?%*:|\"<>\\s]".toRegex(), "_")

Tests

  1. I sent a file containing Cyrillic characters in Element Web.
  2. I viewed that message in Element Android
  3. I clicked the share button for that file.
  4. I verified that the file name in the share UI was not all underscores.

I also wrote unit tests to verify the new regex works as expected (see the code diff).

Tested devices

  • [X] Physical
  • [X] Emulator
  • OS version(s): Android 15 and Android 5.1

Checklist

  • [X] Changes has been tested on an Android device or Android emulator with API 21
  • [-] UI change has been tested on both light and dark themes
  • [X] Accessibility has been taken into account. See https://github.com/element-hq/element-android/blob/develop/CONTRIBUTING.md#accessibility
  • [X] Pull request is based on the develop branch
  • [X] Pull request includes a new file under ./changelog.d. See https://github.com/element-hq/element-android/blob/develop/CONTRIBUTING.md#changelog
  • [X] Pull request includes screenshots or videos if containing UI changes
  • [X] Pull request includes a sign off
  • [X] You've made a self review of your PR
  • [-] If you have modified the screen flow, or added new screens to the application, you have updated the test UiAllScreensSanityTest.allScreensTest()

Signed-off-by: Christian Rowlands <craxiomdev [at] gmail.com>

christianrowlands avatar Oct 16 '24 14:10 christianrowlands

@bmarty , I have another simple PR for you if you can take a look at it. If you have any objections to the new RegEx, I am happy to update it as necessary, or add more tests to verify different scenarios.

christianrowlands avatar Oct 16 '24 14:10 christianrowlands

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Nov 01 '24 13:11 CLAassistant

@christianrowlands can you handle the errors reported by the CI please? Let me know if you need some help.

bmarty avatar Nov 12 '24 15:11 bmarty

Thanks for reviewing!

I will look into the CI failures.

christianrowlands avatar Nov 12 '24 15:11 christianrowlands

@bmarty , give it another run and see if that resolves some or all of the issues.

christianrowlands avatar Nov 12 '24 15:11 christianrowlands

Can you run ./gradlew ktlintFormat first? I think it will remove some unused imports.

bmarty avatar Nov 12 '24 15:11 bmarty

Whoops, I thought I already removed that unused Timber import. I will run it again now.

christianrowlands avatar Nov 12 '24 15:11 christianrowlands

I think you need to either rebase your PR's branch, or merge develop into your branch so that the code can be compiled. We are now using Java 21.

bmarty avatar Nov 12 '24 15:11 bmarty

Ok, I merged develop into my branch. Hopefully we are good now 🤞

christianrowlands avatar Nov 12 '24 15:11 christianrowlands