--- /dev/null
+// Copyright (C) 2017 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using ExpressionToCodeLib;\r
+using Microsoft.VisualStudio.TestTools.UnitTesting;\r
+\r
+namespace KancolleSniffer.Test\r
+{\r
+ [TestClass]\r
+ public class ErrorLogTest\r
+ {\r
+ [TestMethod]\r
+ public void RemoveTokenFromRequest()\r
+ {\r
+ var request =\r
+ "api%5Fverno=1&api%5Ftoken=0123456abcdef&api%5Fport=0123456789";\r
+ var response = "";\r
+ ErrorLog.RemoveUnwantedInformation(ref request, ref response);\r
+ PAssert.That(() => request == "api%5Fverno=1&api%5Fport=0123456789", "トークンが中間");\r
+ var request2 = "api%5Fverno=1&api%5Ftoken=0123456abcdef";\r
+ ErrorLog.RemoveUnwantedInformation(ref request2, ref response);\r
+ PAssert.That(() => request2 == @"api%5Fverno=1", "トークンが末尾");\r
+ var request3 = "api%5Ftoken=0123456abcdef&api%5Fverno=1";\r
+ ErrorLog.RemoveUnwantedInformation(ref request3, ref response);\r
+ PAssert.That(() => request3 == @"api%5Fverno=1", "トークンが先頭");\r
+ var request4 = "api%5Ftoken=0123456abcdef";\r
+ ErrorLog.RemoveUnwantedInformation(ref request4, ref response);\r
+ PAssert.That(() => request4 == "", "トークン単独");\r
+ }\r
+ }\r
+}
\ No newline at end of file
return result;\r
}\r
\r
- private void RemoveUnwantedInformation(ref string request, ref string response)\r
+ public static void RemoveUnwantedInformation(ref string request, ref string response)\r
{\r
- var token = new Regex("&api%5Ftoken=[^&]*|api%5Ftoken=[^&]*&?");\r
+ var token = new Regex("&api%5Ftoken=.+?(?=&|$)|api%5Ftoken=.+?(?:&|$)");\r
request = token.Replace(request, "");\r
var id = new Regex(@"""api_member_id"":\d+,?|""api_nickname"":[^,]+,""api_nickname_id"":""d+"",?");\r
response = id.Replace(response, "");\r