Skip to content

fix: URL-encode programming language filter values in resource list#2079

Merged
tdruez merged 4 commits intoaboutcode-org:mainfrom
uttam282005:fix-resource-filter
Mar 9, 2026
Merged

fix: URL-encode programming language filter values in resource list#2079
tdruez merged 4 commits intoaboutcode-org:mainfrom
uttam282005:fix-resource-filter

Conversation

@uttam282005
Copy link
Contributor

Issues

Changes

URL encoding improvements for programming language filters:

  • Updated links in scan_summary_panel.html to use the urlencode filter for programming language values.
  • Modified the programming language filter link in resource_list.html to use the urlencode filter, preventing issues with special characters.
  • Fixed the JavaScript code in project_charts.html to use encodeURIComponent for programming language values in filter URLs.

Testing for special character handling:

  • Added a test case in test_api.py to verify that programming languages with special characters (e.g., "C#") are correctly filtered and returned by the API when URL-encoded.

Checklist

  • I have read the contributing guidelines
  • I have linked an existing issue above
  • I have added unit tests covering the new code
  • I have reviewed and understood every line of this PR

Signed-off-by: uttam282005 <uttam282005@gmail.com>
Signed-off-by: uttam282005 <uttam282005@gmail.com>
Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uttam282005 Good start, the PR is small and well focused but a few changes are required before merging the code.

  • Fix the JavaScript
  • Add missing unit test for HTML rendering
  • Remove the new lines you've added at the end of the template files
  • Address the API test usefulness

</td>
<td class="break-all">
<a href="?programming_language={{ resource.programming_language }}" class="is-black-link">{{ resource.programming_language }}</a>
<a href="?programming_language={{ resource.programming_language|urlencode }}" class="is-black-link">{{ resource.programming_language }}</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a unit test in ScanPipeViewsTest to make sure the value is properly encoded in the rendered HTML.

Comment on lines 60 to +126
@@ -123,7 +123,7 @@
<ul>
{% for entry in scan_summary.other_languages %}
{% if entry.value %}
<a href="{% url 'project_resources' project.slug %}?programming_language={{ entry.value }}" target="_blank">
<a href="{% url 'project_resources' project.slug %}?programming_language={{ entry.value|urlencode }}" target="_blank">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a unit test in ScanPipeViewsTest to make sure the values are properly encoded in the rendered HTML.

response = self.csrf_client.get(url + "?slug=aaa")
self.assertEqual(2, response.data["count"])

def test_scanpipe_api_project_action_resources_filterset_special_chars(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is unrelated to the PR changes. What's the reasoning behind testing the API in place of testing your code changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was just confirming whether or not special characters are correctly handled in the api. so, thought of adding a test for it.
on second thought django does handle this automatically.
should i remove this test?

Copy link
Contributor

@tdruez tdruez Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine let's keep it. I was just wondering about your intent since the actual changes were not tested.

Signed-off-by: uttam282005 <uttam282005@gmail.com>
@uttam282005
Copy link
Contributor Author

thanks for the review @tdruez i have done the requested changes.

@uttam282005
Copy link
Contributor Author

Remove the new lines you've added at the end of the template files

i haven't added any new lines at the end of the files.
maybe it was added automatically by my editor.
image

@uttam282005 uttam282005 requested a review from tdruez March 9, 2026 05:55
Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, please revert those 2 unwanted leftover changes.

{% endif %}
</script>
{% endblock %} No newline at end of file
{% endblock %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert those type of unwanted changes.

{% endif %}
</div>
{% endblock %} No newline at end of file
{% endblock %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert those type of unwanted changes.

response = self.csrf_client.get(url + "?slug=aaa")
self.assertEqual(2, response.data["count"])

def test_scanpipe_api_project_action_resources_filterset_special_chars(self):
Copy link
Contributor

@tdruez tdruez Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine let's keep it. I was just wondering about your intent since the actual changes were not tested.

Signed-off-by: uttam282005 <uttam282005@gmail.com>
@uttam282005
Copy link
Contributor Author

done.

@uttam282005 uttam282005 requested a review from tdruez March 9, 2026 06:08
Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uttam282005 Looks good, thanks for the fix!

@tdruez tdruez changed the title URL-encode programming language filter values in resource list fix: URL-encode programming language filter values in resource list Mar 9, 2026
@tdruez tdruez merged commit 2090ea0 into aboutcode-org:main Mar 9, 2026
8 checks passed
@uttam282005 uttam282005 deleted the fix-resource-filter branch March 9, 2026 06:19
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.

Resources filter does not work for C# files

2 participants