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

EI-188: Fix ArgumentError (Document tree depth limit exceeded) #2

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/store_search/parsers/play_store_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def description
description = params.description.gsub(/<\s*br\s*\/?\s*>/, "\n") # replace <br/> with \n
description = description.gsub(/(?=<\s*p\s*>)/, "\n") # add \n before <p>
description = description.gsub(/(display\s*:\s*none.*?>)(.*)/m, '\1') # remove text after style="display:none">
HTMLEntities.new.decode Sanitize.fragment(description, Sanitize::Config::RESTRICTED).strip
HTMLEntities.new.decode Sanitize.fragment(description, Sanitize::Config.merge(Sanitize::Config::RESTRICTED,
parser_options: { max_errors: -1, max_tree_depth: -1 }
)).strip
end

def publisher
Expand Down
50 changes: 50 additions & 0 deletions spec/lib/parsers/play_store_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,54 @@ def parse_min_os_version(version)
end
end
end

describe '#description' do
def parse_description(description)
StoreSearch::PlayStoreParser.new(OpenStruct.new(description: description)).description
end

context 'when description is usual' do
it 'returns parsed and decoded description' do
description = '<html> <h1>&bdquo;&#9733; some<br>more <br/>description<p>and</p> other<br />stuff &#9733;&ldqu'\
'o;</h1> hidden<div style="display: none;">text </html>'
expect(parse_description(description)).to eq("„★ some\nmore \ndescription\n and other\nstuff ★“ hidden")
end
end

context 'when description exceeds default tree depth limit' do
it 'returns parsed and decoded description' do
description = '<span jsslot><div jsname=\"sngebd\">Backgammon is one of the world&rsquo;s most popular board g'\
'ames, brought to you by the makers of Nonogram.com and Sudoku.com puzzles. Install Backgammon for free now, t'\
'rain your brain and have fun!\n\nBackgammon board game (also known as Nardi or Tawla ) is one of the oldest l'\
'ogic games in existence, alongside Chess and Go. People from all over the world have been playing backgammon '\
'classic for more than 5000 years to socialize with family and friends and keep their brains active.\n\nHow to'\
' play the Backgammon classic game\n\n- Classic Backgammon is a logic puzzle for two, played on a board of 24 '\
'triangles. These triangles are called points.\n- Each player sits on the opposite sides of the board with 15 '\
'checkers, black or white.\n- To start the game, players take turns and roll the dice. That&rsquo;s why free B'\
'ackgammon is often called a dice game.\n- Players move pieces based on the numbers rolled. For example, if yo'\
'u roll 2 and 5, you can move one piece 2 points and another one 5 points. Alternatively, you can move one pie'\
'ce 7 points.\n- Once all of a player&rsquo;s pieces are on the opponent&rsquo;s &ldquo;home&rdquo;, that play'\
'er may begin removing pieces off of the board.\n- A player wins once all of their pieces are removed from the'\
' board\n\nA few more things to know\n\n- Rolling two of the same number allows you to move 4 times. For examp'\
'le, for a roll of 4 and 4, you can move a total of 16 points, although each piece must move 4 points at a tim'\
'e.\n- You cannot move a piece to a point that is occupied by 2 or more of your opponent&rsquo;s pieces\n- If '\
'you move a piece to a point with only 1 of your opponent&rsquo;s pieces on it, the rival&rsquo;s piece is rem'\
'oved from the board and placed on the middle partition.\n\nBackgammon Free Features\n\n- Enjoy a fair dice ro'\
'll, which only the best backgammon games can boast.\n- Undo a move if you made it accidentally or came up wit'\
'h a better one right after\n- Your possible moves are highlighted to help you make an easier decision\n- A si'\
'mple and intuitive design to better focus on the game\n- Start with easy opponents and face more difficult on'\
'es as you practice on your way to becoming the Backgammon king.\n\nInteresting facts about Backgammon\n\n- An'\
'cient Romans, Greeks, and Egyptians all loved playing Backgammon (known as tawla or narde). \n- Backgammon is'\
' a classic game of luck and strategy. While any dice game is pretty much pure luck, there&rsquo;s also an inf'\
'inite number of strategies that even include predicting your opponent&rsquo;s moves.\n- One thing logic games'\
' have in common &ndash; they keep your brain sharp. It may not be difficult to learn the basics of Backgammon'\
', but you&rsquo;ll need an entire lifetime to become a true lord of the board.\n\nBackgammon Classic is one o'\
'f the most popular free board games ever. Download it now and challenge yourself!</div></span><div jsname=\"W'\
'gKync\" class=\"uwAgLc f3Fr9d\"></div>'

expect(parse_description(description)).to start_with('Backgammon is one of the world’s most popular')
expect(parse_description(description)).to end_with('Download it now and challenge yourself!')
end
end
end
end