summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason M. Bills <jason.m.bills@linux.intel.com>2019-12-11 14:32:14 -0800
committerJason Bills <jason.m.bills@linux.intel.com>2019-12-17 19:00:58 +0000
commita6e2f1c4cba5f3b19d7c039f52d6598b129b5b10 (patch)
treee7751f82dc31eac7f9ecdfb9455fa0e78847674f
parent85cc8de632cbd75fd52d060574241664a08faa9a (diff)
downloadbmcweb-a6e2f1c4cba5f3b19d7c039f52d6598b129b5b10.tar.gz
bmcweb-a6e2f1c4cba5f3b19d7c039f52d6598b129b5b10.zip
Consolidate regex calls when converting links
We currently use multiple regex calls to convert specific fields to links. Rather than continuing to add new regex calls for individual link types, we can use one regex to convert all '/redfish/' paths to links. Tested: Checked that all provided redfish paths are converted to links: odata.id, odata.context, nextLink, Uri, etc. Change-Id: I2f06e2d5ee9b3d88141f1629f168b3667669d93f Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
-rw-r--r--http/utility.h17
1 files changed, 5 insertions, 12 deletions
diff --git a/http/utility.h b/http/utility.h
index ee88e5a..c71187d 100644
--- a/http/utility.h
+++ b/http/utility.h
@@ -738,18 +738,11 @@ inline void escapeHtml(std::string& data)
inline void convertToLinks(std::string& s)
{
- const static std::regex r{"(&quot;@odata\\.((id)|(Context))&quot;[ \\n]*:[ "
- "\\n]*)(&quot;((?!&quot;).*)&quot;)"};
- s = std::regex_replace(s, r, "$1<a href=\"$6\">$5</a>");
-
- const static std::regex nextLink{
- "(&quot;Members@odata\\.((nextLink))&quot;[ \\n]*:[ "
- "\\n]*)(&quot;((?!&quot;).*)&quot;)"};
- s = std::regex_replace(s, nextLink, "$1<a href=\"$5\">$4</a>");
-
- const static std::regex uri{"(&quot;((Uri))&quot;[ \\n]*:[ "
- "\\n]*)(&quot;((?!&quot;).*)&quot;)"};
- s = std::regex_replace(s, uri, "$1<a href=\"$5\">$4</a>");
+ // Convert anything with a redfish path into a link
+ const static std::regex redfishPath{
+ "(&quot;((.*))&quot;[ \\n]*:[ "
+ "\\n]*)(&quot;((?!&quot;)/redfish/.*)&quot;)"};
+ s = std::regex_replace(s, redfishPath, "$1<a href=\"$5\">$4</a>");
}
/**
OpenPOWER on IntegriCloud