wordpress-mobile / wordpress-mobile/AztecEditor-iOS

TextView crashes app because textAttachmentDelegate? not set.

Open
#1,397 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
669
Forks
153
Avg merge
11h 27m
Merged PRs (30d)
4

Description

Describe the bug

TextView func storage(_ storage: TextStorage, placeholderFor attachment: NSTextAttachment) -> UIImage is crashing my app in production of the following guard statement contains a fatalError.

        guard let textAttachmentDelegate = textAttachmentDelegate else {
            fatalError("This class requires a text attachment delegate to be set.")
        }

        return textAttachmentDelegate.textView(self, placeholderFor: attachment)

The problem with this is that earlier in the file the following is explicitly stated for the textAttachmentDelegate optional.

    /// The media delegate takes care of providing remote media when requested by the `TextView`.
    /// If this is not set, all remove images will be left blank.
    ///
    open weak var textAttachmentDelegate: TextViewAttachmentDelegate?

Which would imply that the TextView will continue to function, only without displaying images. Not fatalError crashing.

This seems to be the case with all of the storage functions.

To Reproduce
Steps to reproduce the behavior:
1.

Create an instance of the TextView without instantiating textAttachmentDelegate

  1. Render the Field in a SwiftUI view.

Expected behavior
A clear and concise description of what you expected to happen.

A TextView should continue to run rendering the HTML and images remain blank, WITHOUT crashing the app, as implied by the documentation. (Unless there is actually something called 'remove images'.)

Screenshots
If applicable, add screenshots to help explain your problem.
simulator_screenshot_BCB48876-BD8C-45A0-AE68-F9D31201CD38

Smartphone (please complete the following information):

  • Device: iPhone 15 Pro
  • OS: 17.5.1

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate TextView's storage(_:placeholderFor:) implementation and the other storage functions mentioned in the report. Compare their fatalError behavior with the textAttachmentDelegate documentation, then verify that rendering a SwiftUI TextView without the delegate no longer crashes and leaves remote images blank.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.