Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Commit

Permalink
Add README documentation and changelog entry about attribute limit
Browse files Browse the repository at this point in the history
  • Loading branch information
rafbm authored and stevecheckoway committed May 5, 2020
1 parent 66b8fad commit 28c5940
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Added
- Limit enforced on number of attributes per element, defaulting to 400 and
configurable with the `:max_attributes` argument.

### Changed
### Deprecated
### Removed
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ doc = Nokogiri.HTML5(html)
doc = Nokogiri.HTML5(html, max_tree_depth: -1)
```

### Attribute limit per element
The maximum number of attributes per DOM element is configurable by the
`:max_attributes` option. If a given element would exceed this limit, then an
[ArgumentError](https://ruby-doc.org/core-2.5.0/ArgumentError.html) is thrown.

This limit (which defaults to `Nokogumbo::DEFAULT_MAX_ATTRIBUTES = 400`) can
be removed by giving the option `max_attributes: -1`.

``` ruby
html = '<!DOCTYPE html><div ' + (1..1000).map { |x| "attr-#{x}" }.join(' ') + '>'
# "<!DOCTYPE html><div attr-1 attr-2 attr-3 ... attr-1000>"
doc = Nokogiri.HTML5(html)
# raises ArgumentError: Attributes per element limit exceeded
doc = Nokogiri.HTML5(html, max_attributes: -1)
```

## HTML Serialization

After parsing HTML, it may be serialized using any of the Nokogiri
Expand Down

0 comments on commit 28c5940

Please sign in to comment.