From df85ed48e5e94449cdcc77de3b86e10ccea49f1e Mon Sep 17 00:00:00 2001 From: Aravinda VK Date: Mon, 3 Jul 2017 14:51:21 +0530 Subject: tools/glusterfind: Fix encoding to encode only space,newline and percent chars libgfchangelog was encoding path using spec rfc3986, but encoding only required for SPACE, NEWLINE and PERCENT chars since the NEWLINE char is used as record separator and SPACE as field separator in the parsed changelogs output. Changed the encoding function to encode only SPACE, NEWLINE and PERCENT chars BUG: 1451724 Change-Id: Ic1dea824d23493dedcf3db45f353f90572f4e046 Signed-off-by: Aravinda VK Reviewed-on: https://review.gluster.org/17788 CentOS-regression: Gluster Build System Smoke: Gluster Build System Reviewed-by: Milind Changire --- tools/glusterfind/src/utils.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'tools/glusterfind/src/utils.py') diff --git a/tools/glusterfind/src/utils.py b/tools/glusterfind/src/utils.py index b08233e4a9f..c24258e6ef8 100644 --- a/tools/glusterfind/src/utils.py +++ b/tools/glusterfind/src/utils.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2015 Red Hat, Inc. @@ -16,10 +15,12 @@ import xml.etree.cElementTree as etree import logging import os from datetime import datetime -import urllib ROOT_GFID = "00000000-0000-0000-0000-000000000001" DEFAULT_CHANGELOG_INTERVAL = 15 +SPACE_ESCAPE_CHAR = "%20" +NEWLINE_ESCAPE_CHAR = "%0A" +PERCENTAGE_ESCAPE_CHAR = "%25" ParseError = etree.ParseError if hasattr(etree, 'ParseError') else SyntaxError cache_data = {} @@ -84,7 +85,7 @@ def output_write(f, path, prefix=".", encode=False, tag="", path = os.path.join(prefix, path) if encode: - path = urllib.quote_plus(path) + path = quote_plus_space_newline(path) # set the field separator FS = "" if tag == "" else field_separator @@ -246,4 +247,16 @@ def output_path_prepare(path, args): if args.no_encode: return path else: - return urllib.quote_plus(path.encode("utf-8")) + return quote_plus_space_newline(path) + + +def unquote_plus_space_newline(s): + return s.replace(SPACE_ESCAPE_CHAR, " ")\ + .replace(NEWLINE_ESCAPE_CHAR, "\n")\ + .replace(PERCENTAGE_ESCAPE_CHAR, "%") + + +def quote_plus_space_newline(s): + return s.replace("%", PERCENTAGE_ESCAPE_CHAR)\ + .replace(" ", SPACE_ESCAPE_CHAR)\ + .replace("\n", NEWLINE_ESCAPE_CHAR) -- cgit