[PR #1052] [MERGED] Fix: keep blank values as True to handle blank 'q' input. #1063

Closed
opened 2026-02-25 20:37:33 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/benbusby/whoogle-search/pull/1052
Author: @ahmad-alkadri
Created: 8/13/2023
Status: Merged
Merged: 8/21/2023
Merged by: @benbusby

Base: mainHead: fix/1050-handle-filter-blank-query


📝 Commits (1)

  • 504ff35 Fix: keep blank values = True to handle blank 'q' input.

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 app/filter.py (+1 -1)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/benbusby/whoogle-search/pull/1052 **Author:** [@ahmad-alkadri](https://github.com/ahmad-alkadri) **Created:** 8/13/2023 **Status:** ✅ Merged **Merged:** 8/21/2023 **Merged by:** [@benbusby](https://github.com/benbusby) **Base:** `main` ← **Head:** `fix/1050-handle-filter-blank-query` --- ### 📝 Commits (1) - [`504ff35`](https://github.com/benbusby/whoogle-search/commit/504ff35c49abf45b402a1baae25072a8ba389b2d) Fix: keep blank values = True to handle blank 'q' input. ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `app/filter.py` (+1 -1) </details> ### 📄 Description This PR fixes (potentially) Issue #1050. Location of the bug found at the function: ```python #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: ```python # 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](https://github.com/benbusby/whoogle-search/assets/22837764/1b6c5877-c684-47c6-8218-ba60be8d7378) ![image](https://github.com/benbusby/whoogle-search/assets/22837764/165e442d-ce5d-45a6-8e31-17ce86a20bea) Open to discussions and modifications if needed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-25 20:37:33 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/whoogle-search#1063
No description provided.