CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes <https://cwe.mitre.org/data/definitions/915.html> (Ruby on Rails Mass assignment bug)
Regarding attributes that you defined but still don't want to be assigned, you should probably filter them before passing them to Shale, or alternatively filter them with Shale before passing them further down the stack (e.g to ActiveRecord)
<meta name="description" content="Vue-powered Static Site Generator">
Kudos for choosing Vue tho =)
Regarding Vue I use it daily at my job, great library :)
I'll probably give it a go to replace my current implementation using nokogiri-happymapper (https://github.com/mvz/happymapper)
But you can just give an upgrade path! consider something like this:
class Address
attr_accessor :street, :city
end
class Person
attr_accessor :address
end
class AddressMapper < Shale::Mapper
mapped_class Address
attribute :street, Shale::Type::String
attribute :city, Shale::Type::String
end
class PersonMapper < Shale::Mapper
mapped_class Person
attribute :address, AddressMapper
end
# use like this
PersonMapper.from_xml("...."); PersonMapper.to_xml(person)
and then, for _dead_ simplicity, you can add another method
generate_mapped_class "Person"which will define that PORO class for user for extra DRYness. API is basically the same, no repetition, but amount of rewrite with new requirements is drastically less.
I'm not asking you to rewrite your library, and I probably won't write and release mine, just saying that considering future self isn't that hard. And yeah, it's a bit of a rant about ActiveRecord from user of Rails, since 2006.
*Edit: nice docs site as well - what are you using for it?
Interactive examples are powered by https://opalrb.com/
See http://www.ruby-lang.org/en/news/2021/04/05/xml-round-trip-v...
class Person < Shale::Mapper
attribute :first_name, Shale::Type::String
attribute :last_name, Shale::Type::String
attribute :age, Shale::Type::Integer
attribute :married, Shale::Type::Boolean, default: false
attribute :hobbies, Shale::Type::String, collection: true
attribute :address, Address
end
And the JSON used for parsing also should contain those atttributes, like: {
"first_name": "John",
"last_name": "Doe",
"age": 30,
"married": false,
"hobbies": ["Singing", "Dancing"],
"address": {
"street": "Oxford Street",
"city": "London"
}
}