Extract native share-file preparation from AndroidDocumentsPlugin#93
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eighth and final PR of the semantic-decomposition series: moves Markdown share preparation out of
AndroidDocumentsPlugin.javainto a focusedSharePreparationhelper. Behavior-preserving — file names, cache layout, FileProvider authority, ClipData shape, and log lines are unchanged.Boundary
SharePreparationowns:shared-markdownunder the app cache),.mdnormalization,marktext-image://local/link rewrite with its missing-file skip — and byte-for-byte attachment copying with unsafe-name rejection,ClipDataconstruction over the prepared stream URIs.ShareMarkdownPayloadbecomes a package-visible top-level class (same pattern as #91's value types). Two placement calls worth noting:normalizeSuggestedMarkdownNamemoves 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; likewisehasSupportedImageExtension/normalizeImportedImageFileNamemove 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_MULTIPLEintent with titles/flags, exclude the app from its own chooser, start the activity, and resolve the call.Testing
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-traversalSecurityExceptionguard. Native suite now 19/19 (MarkdownCodecTest8 +IncomingIntentParserTest5 + these 6), CI-gated since Extract native Markdown codec from AndroidDocumentsPlugin #91.shareMarkdownDocumentsreceived 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+assembleDebuggreen; Java-only diff, TS contract untouched.