Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested attributed intrinsic #78

Closed
MaxDesiatov opened this issue Feb 23, 2019 · 2 comments · Fixed by #79
Closed

Fix nested attributed intrinsic #78

MaxDesiatov opened this issue Feb 23, 2019 · 2 comments · Fixed by #79
Assignees

Comments

@MaxDesiatov
Copy link
Collaborator

As reported in #12 by @thecb4:

A standalone XML element with attributed intrinsic works. When it's embedded in another element, it fails.

// This passes
  let previewTime = 
  """
  <?xml version="1.0" encoding="UTF-8"?>
  <preview_image_time format="24/999 1000/nonDrop">00:00:17:01</preview_image_time>
  """.data(using: .utf8)!


  let decoder = XMLDecoder()
  decoder.errorContextLength = 10

  let metadata1 = try decoder.decode(PreviewImageTime.self, from: previewTime)
  print(metadata1)

// this does not pass
  let preview = 
  """
  <?xml version="1.0" encoding="UTF-8"?>
  <app_preview display_target="iOS-6.5-in" position="1">
    <preview_image_time format="24/999 1000/nonDrop">00:00:17:01</preview_image_time>
  </app_preview>
  """.data(using: .utf8)!

  let metadata2 = try decoder.decode(AppPreview.self, from: preview)
  print(metadata2)

structs:

struct AppPreview: Codable {
  var displayTarget: String
  var position: Int
  var previewImageTime: PreviewImageTime
  // var dataFile: DataFile

  enum CodingKeys: String, CodingKey {
    case displayTarget = "display_target"
    case position
    case previewImageTime = "preview_image_time"
    // case dataFile = "data_file"
  }
}

struct PreviewImageTime: Codable, DynamicNodeEncoding {

  var format: String
  var value: String

  enum CodingKeys: String, CodingKey {
    case format
    case value
  }

  static func nodeEncoding(forKey key: CodingKey) -> XMLEncoder.NodeEncoding {
    print("node encoding")
    switch key {
      case CodingKeys.format:
        return .attribute
      default:
        return .element
    }
  }
}
@MaxDesiatov MaxDesiatov self-assigned this Feb 23, 2019
MaxDesiatov added a commit that referenced this issue Feb 23, 2019
Existing `flatten` implementation wasn't correctly handling element values, this is now fixed.

Fixes #78 

* Fix nested attributed intrinsic
* Cleanup new `AppPreview` test
@MaxDesiatov
Copy link
Collaborator Author

@thecb4 this should be now fixed and is verified with a test based on the code you've provided. Please let me know if this is still reproducible for you in master.

@thecb4
Copy link

thecb4 commented Feb 23, 2019

Works!

output now

AppPreview(displayTarget: "iOS-6.5-in", position: 1, previewImageTime: test.PreviewImageTime(format: "24/999 1000/nonDrop", value: "00:00:17:01"))

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 a pull request may close this issue.

2 participants