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: keep blank values as True to handle blank 'q' input. #1052

Merged

Conversation

ahmad-alkadri
Copy link
Contributor

This PR fixes (potentially) Issue #1050.

Location of the bug found at the function:

#app/filter.py

def extract_q(q_str: str, href: str) -> str:
    """Extracts the 'q' element from a result link. This is typically
    either the link to a result's website, or a string.

    Args:
        q_str: The result link to parse
        href: The full url to check for standalone 'q' elements first,
              rather than parsing the whole query string and then checking.

    Returns:
        str: The 'q' element of the link, or an empty string
    """

    return parse_qs(q_str)['q'][0] if ('&q=' in href or '?q=' in href) else ''

What happened when searching the query “Mathias Normann” (and potentially could be other queries) is that the href contains "q" but the value is blank in both href and q_str as follows:

# href:
"/search?safe=off&sca_esv=556514156&gbv=1&q=&si=ACFMAn9guiESjt..."

# q_str:
"safe=off&sca_esv=556514156&gbv=1&q=&si=ACFMAn9guiESjt..."

Thus, the value of ‘q’ would be blank.

By default, the function parse_qs will not keep the blank values nor keys, thus making the resulting parse_qs(q_str)['q'][0] throwing a KeyError because the key ‘q’ is simply not there.

To fix this, I simply put the keep_blank_values parameter of the parse_qs function into True. This fixes the problem.

Some screenshots:

image

image

Open to discussions and modifications if needed.

@benbusby benbusby linked an issue Aug 21, 2023 that may be closed by this pull request
8 tasks
@benbusby benbusby merged commit 4a00896 into benbusby:main Aug 21, 2023
2 checks passed
@ahmad-alkadri ahmad-alkadri deleted the fix/1050-handle-filter-blank-query branch August 22, 2023 17:51
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.

[BUG] 500 Internal Server Error
2 participants