Skip to content

Commit

Permalink
- ios-sdk update: fixes crash (finding #1 in #1298)
Browse files Browse the repository at this point in the history
- ScanViewController, NamingViewController: when enforcing file suffixes: prevent choice of filenames consisting just of a suffix (since these would be hidden files) by disabling the primary action button
  • Loading branch information
felix-schwarz committed Nov 22, 2023
1 parent 22641d8 commit 5b57fda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ios-sdk
10 changes: 8 additions & 2 deletions ownCloud/Client/Actions/Scanner/ScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ class ScanViewController: StaticTableViewController {
self.isModalInPresentation = true
self.navigationItem.title = "Scan".localized
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(ScanViewController.cancel))
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(ScanViewController.save))

let saveBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(ScanViewController.save))
self.navigationItem.rightBarButtonItem = saveBarButtonItem

self.core = core
self.targetFolderItem = item
Expand Down Expand Up @@ -358,7 +360,7 @@ class ScanViewController: StaticTableViewController {
// Save section

// - Name
fileNameRow = StaticTableViewRow(textFieldWithAction: { [weak self] (row, textField, type) in
fileNameRow = StaticTableViewRow(textFieldWithAction: { [weak self, weak saveBarButtonItem] (row, textField, type) in
self?.navigationItem.rightBarButtonItem?.isEnabled = ((row.value as? String)?.count ?? 0) > 0

if type == .didBegin, let nameTextField = textField as? UITextField {
Expand All @@ -374,6 +376,10 @@ class ScanViewController: StaticTableViewController {
nameTextField.selectedTextRange = nameTextField.textRange(from: nameTextField.beginningOfDocument, to: nameTextField.endOfDocument)
}
}

if let fileName = (textField as? UITextField)?.text, let requiredFileExtension = row.requiredFileExtension {
saveBarButtonItem?.isEnabled = (fileName.count > (requiredFileExtension.count + 1))
}
}, placeholder: "Name".localized, value: fileName ?? "", keyboardType: .default, autocorrectionType: .no, enablesReturnKeyAutomatically: true, returnKeyType: .default, identifier: "name", accessibilityLabel: "Name".localized)
saveSection.add(row: fileNameRow!)
self.addSection(saveSection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ open class NamingViewController: UIViewController {
}

@objc open func textfieldDidChange(_ sender: UITextField) {
if sender.text != "" {
let filename = sender.text

if filename != "", requiredFileExtension == nil || ((requiredFileExtension != nil) && filename != ".\(requiredFileExtension!)") {
doneButton?.isEnabled = true
} else {
doneButton?.isEnabled = false
Expand Down

0 comments on commit 5b57fda

Please sign in to comment.