From f923e095352f1be55d0c3658e55472271ed4d8b3 Mon Sep 17 00:00:00 2001 From: "Jonathan S. Katz" Date: Mon, 12 Oct 2020 14:00:09 -0400 Subject: [PATCH] Allow for direct URLs to abbreviated legacy PostgreSQL releases For example, while a link to "/docs/release/9.1.0/" would work, going to "/docs/release/9.1/" would not; in this case, it would show the release details for "9.0.1". While the probability of someone modifying the links to see the different release notes is low, we would still need to take action on what is an incorrect link. Instead of returning a 404, this transposes the major/minor version to point at the canonical version number and render the expected page. This is set up to work for the 6, 7, 8, 9 series. Reported by: Nikolay Samokhvalov --- pgweb/docs/views.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pgweb/docs/views.py b/pgweb/docs/views.py index 94294cb9..ef196a17 100644 --- a/pgweb/docs/views.py +++ b/pgweb/docs/views.py @@ -268,6 +268,16 @@ def release_notes(request, major_version=None, minor_version=None): # notes # otherwise ensure the release notes are returned in order if major_version is not None and minor_version is not None: + # a quick check to see if major is one of 6 - 9 as a whole number. If + # it is, this may be because someone is trying to up a major version + # directly from the URL, e.g. "9.1", even through officially the release + # number was "9.1.0". + # anyway, we shouldn't 404, but instead transpose from "9.1" to "9.1.0". + # if it's not an actual PostgreSQL release (e.g. "9.9"), then it will + # 404 at a later step. + if major_version in ['6', '7', '8', '9']: + major_version = "{}.{}".format(major_version, minor_version) + minor_version = '0' # at this point, include the content sql = sql.format(content="content,") # restrict to the major version, order from latest to earliest minor