Repository navigation
Define a constant instead of duplicating 'http://%s' (Sonar S1192) - #565
Merged
Merged
Conversation
settings_base.py repeated the 'http://%s' format string at SITE_URL, SERVICES_URL and ES_URLS. Introduce one module-level _http_url_format constant and use it at all three sites with identical % formatting; the lowercase leading-underscore name keeps Django from exposing it as a setting. No behavior change: each of the three expressions evaluates to the exact same value as before.
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes
python:S1192onsrc/olympia/lib/settings_base.py:229("Define a constant instead of duplicating this literal 'http://%s' 3 times", Sonar issue keyAaEh92ixMSBE_HpBvX1E).Introduces a single module-level
_http_url_format = 'http://%s'constant and uses it at all three duplicate sites (lines 229, 237, 1524). The name is lowercase with a leading underscore so Django's settings machinery does not pick it up as a setting (uppercase names in this module become settings and show up in zadmin's settings page).Equivalence
No behavior change. Each of the three expressions evaluates to the byte-identical value as before:
SITE_URL = _http_url_format % DOMAIN=='http://%s' % DOMAINSERVICES_URL = _http_url_format % SERVICES_DOMAIN=='http://%s' % SERVICES_DOMAINES_URLS = [_http_url_format % h for h in ES_HOSTS]==['http://%s' % h for h in ES_HOSTS]_http_url_formatholds the exact same string literal used at each site, so the%formatting operands and results are unchanged.Context
python:S1192on this file was explicitly declined for exclusion in the thunderbird/addons-server#449 register ("a no-behavior-change fix exists"). The companionpython:S5332("Using HTTP protocol is insecure") new-code flag this refactor would otherwise trigger is covered by an accepted exclusion in that same register (python:S5332/src/olympia/lib/settings_base.py, 4 occurrences), applied to the project today.No other change in the file.