Skip to content

Handle extra attributes in element 'a'#7

Open
eli-hu wants to merge 1 commit intomphilli:masterfrom
eli-hu:handle-extra-attributes-in-element-a
Open

Handle extra attributes in element 'a'#7
eli-hu wants to merge 1 commit intomphilli:masterfrom
eli-hu:handle-extra-attributes-in-element-a

Conversation

@eli-hu
Copy link
Copy Markdown

@eli-hu eli-hu commented Mar 28, 2021

The response coming back from LoC is looking like this:
<td><a href="/authorities/term_id_is_here" title="Click to view record">
instead of like this:
<td><a href="/authorities/term_id_is_here">
so the term_id is getting set to:
term_id_is_here" title="Click to view record
because the regex "/(.+)\">" is greedily taking everything up to the last " before the >.

This commit changes the regex to "/([^\"]+)\"[^>]*>" which searches for /, followed by
one or more characters that are not ", followed by ", followed by zero or more characters
that are not >, followed by >. The group will now take only up to the first double quote
character, so it will work no matter what other attributes are within the <a> element.

The response coming back from LoC is looking like this:
`<td><a href="/authorities/term_id_is_here" title="Click to view record">`
instead of like this:
`<td><a href="/authorities/term_id_is_here">`
so the term_id is getting set to:
`term_id_is_here" title="Click to view record`
because the regex `"/(.+)\">"` is greedily taking everything up to the last `"` before the `>`.

This commit changes the regex to `"/([^\"]+)\"[^>]*>"` which searches for `/`, followed by
one or more characters that are not `"`, followed by `"`, followed by zero or more characters
that are not `>`, followed by `>`. The group will now take only up to the first double quote
character, so it will work no matter what other attributes are within the `<a>` element.
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 this pull request may close these issues.

1 participant