Skip to content

Extract native share-file preparation from AndroidDocumentsPlugin#93

Merged
Renakoni merged 1 commit into
mainfrom
refactor/native-share-preparation
Jul 10, 2026
Merged

Extract native share-file preparation from AndroidDocumentsPlugin#93
Renakoni merged 1 commit into
mainfrom
refactor/native-share-preparation

Conversation

@Renakoni

Copy link
Copy Markdown
Owner

Summary

Eighth and final PR of the semantic-decomposition series: moves Markdown share preparation out of AndroidDocumentsPlugin.java into a focused SharePreparation helper. Behavior-preserving — file names, cache layout, FileProvider authority, ClipData shape, and log lines are unchanged.

Boundary

SharePreparation owns:

  • the share-cache directory (shared-markdown under the app cache),
  • temporary Markdown file writing behind the canonical-path containment guard,
  • case-insensitive unique in-batch file naming and the suggested-name → safe-.md normalization,
  • image attachment collection — the marktext-image://local/ link rewrite with its missing-file skip — and byte-for-byte attachment copying with unsafe-name rejection,
  • ClipData construction over the prepared stream URIs.

ShareMarkdownPayload becomes a package-visible top-level class (same pattern as #91's value types). Two placement calls worth noting: normalizeSuggestedMarkdownName moves here as the front half of the TODO's "unique file naming" concern — the create/rename/shared-text call sites now reference it cross-feature rather than duplicating the rule; likewise hasSupportedImageExtension/normalizeImportedImageFileName move with their only remaining callers so the extension list cannot drift between share preparation and image import.

Per the TODO, the plugin keeps the final Capacitor and Android dispatch: both share plugin methods still validate through the codec, assemble the SEND/SEND_MULTIPLE intent with titles/flags, exclude the app from its own chooser, start the activity, and resolve the call.

Testing

  • New SharePreparationTest (6 JUnit tests): suggested-name sanitization/extension handling, case-insensitive batch deduplication with extension-aware suffixes, unsafe imported-image-name rejection (traversal, wrong extension, null), the supported-extension rule, byte-for-byte attachment copying into a temp directory, and the path-traversal SecurityException guard. Native suite now 19/19 (MarkdownCodecTest 8 + IncomingIntentParserTest 5 + these 6), CI-gated since Extract native Markdown codec from AndroidDocumentsPlugin #91.
  • Emulator smoke: long-press-selected two drafts and shared through the UI — shareMarkdownDocuments received both payloads and the new helper produced the share sheet end to end (Opened Android share sheet for 2 Markdown documents), exercising cache-dir creation, unique naming, cache writes, and ClipData on device.
  • compileDebugJavaWithJavac + assembleDebug green; Java-only diff, TS contract untouched.

Moves Markdown share preparation into a focused SharePreparation helper:
the share-cache directory, temporary Markdown file writing behind the
path-containment guard, case-insensitive unique in-batch file naming,
suggested-name normalization, image attachment collection (the
marktext-image link rewrite with its missing-file skip) and byte-for-
byte attachment copying, and the ClipData built over the prepared
stream URIs. ShareMarkdownPayload becomes a package-visible top-level
class, and the supported-image-extension rule moves along with its only
remaining callers so the list cannot drift between share and import.

The plugin keeps the final Capacitor handling and the Android share
Intent dispatch: both share plugin methods still validate through the
codec, assemble the SEND/SEND_MULTIPLE intent, exclude the app from its
own chooser, and resolve the call. File names, cache layout, provider
authority, ClipData shape, and log lines are unchanged.

Adds SharePreparationTest (6 JUnit tests) for name normalization,
batch-name deduplication, unsafe-image-name rejection, extension rules,
byte-for-byte attachment copying, and the path-traversal guard;
multi-document sharing was smoke-verified on the emulator end to end
through the new helper.
@Renakoni Renakoni merged commit d6dfd17 into main Jul 10, 2026
5 checks passed
@Renakoni Renakoni deleted the refactor/native-share-preparation branch July 10, 2026 14:28
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.

1 participant