[Ttssh2-commit] [6413] strreplace で正しく無い正規表現の場合は result で -1 を返すように変更した。

svnno****@sourc***** svnno****@sourc*****
2016年 6月 27日 (月) 13:26:24 JST


Revision: 6413
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6413
Author:   doda
Date:     2016-06-27 13:26:24 +0900 (Mon, 27 Jun 2016)
Log Message:
-----------
strreplace で正しく無い正規表現の場合は result で -1 を返すように変更した。

Modified Paths:
--------------
    trunk/doc/en/html/about/history.html
    trunk/doc/en/html/macro/command/strreplace.html
    trunk/doc/ja/html/about/history.html
    trunk/doc/ja/html/macro/command/strreplace.html
    trunk/teraterm/ttpmacro/ttl.c

Added Paths:
-----------
    trunk/tests/#36405-strreplace.ttl

-------------- next part --------------
Modified: trunk/doc/en/html/about/history.html
===================================================================
--- trunk/doc/en/html/about/history.html	2016-06-27 04:26:21 UTC (rev 6412)
+++ trunk/doc/en/html/about/history.html	2016-06-27 04:26:24 UTC (rev 6413)
@@ -42,7 +42,10 @@
   <li>Bug fixes
     <ul>
       <li>Tera Term(ttermpro.exe) can not run on Windows 95/98/Me/NT4.0.</li>
-      <li>MACRO: When invalid regular expression is specified at the <a href="../macro/command/strreplace.html">strreplace</a> command, source string is corrupted.</li>
+      <li>MACRO: When invalid regular expression is specified at the <a href="../macro/command/strreplace.html">strreplace</a> command, source string is corrupted.
+        <!-- ul>
+          <li>\x90\xB3\x82\xB5\x82\xAD\x96\xB3\x82\xA2\x90\xB3\x8BK\x95\\x8C\xBB\x82\xF0\x8Ew\x92肵\x82\xBD\x8E\x9E\x82\xCD result \x82\xC5 -1 \x82\xF0\x95Ԃ\xB7\x82悤\x82ɂ\xB5\x82\xBD\x81B</li>
+        </ul --></li>
     </ul>
   </li>
 

Modified: trunk/doc/en/html/macro/command/strreplace.html
===================================================================
--- trunk/doc/en/html/macro/command/strreplace.html	2016-06-27 04:26:21 UTC (rev 6412)
+++ trunk/doc/en/html/macro/command/strreplace.html	2016-06-27 04:26:24 UTC (rev 6413)
@@ -34,6 +34,12 @@
 When the replacing succeeds, the system variable "result" is set to 1 and the matched string by the &lt;regex&gt; is stored into the system variable "matchstr". <br>
 When the replacing fails, the system variable "result" is set to 0.
 </p>
+<!-- p>
+\x92u\x8A\xB7\x82\xAA\x90\xAC\x8C\x{1C2DC2}\xE9\x82ƁA\x83V\x83X\x83e\x83\x80\x95ϐ\x94 result \x82\xC9 "1" \x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x81A\x90\xB3\x8BK\x95\\x8C\xBB &lt;regex&gt; \x82Ń}\x83b\x83`\x82\xB5\x82\xBD\x95\xB6\x8E\x9A\x97\xF1\x82̓V\x83X\x83e\x83\x80\x95ϐ\x94 matchs
+tr \x82Ɋi\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+&lt;regex&gt; \x82\xAA &lt;strvar&gt; \x82̓\xE0\x97e\x82Ƀ}\x83b\x83`\x82\xB9\x82\xB8\x92u\x8A\xB7\x82\xAA\x8Ds\x82\xED\x82\xEA\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x82́Aresult \x82\xC9 "0" \x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+&lt;regex&gt; \x82̏\x91\x8E\xAE\x82\xAA\x90\xB3\x82\xB5\x82\xAD\x82Ȃ\xA2\x93\x99\x82ŃG\x83\x89\x81[\x82ƂȂ\xC1\x82\xBD\x8Fꍇ\x82́Aresult \x82\xC9 "-1" \x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B
+</p -->
 
 <p>
 When a user searches the multi-byte string like as Japanese, the user must configure the regular encoding by using the <a href="regexoption.html">regexoption</a> previously.

Modified: trunk/doc/ja/html/about/history.html
===================================================================
--- trunk/doc/ja/html/about/history.html	2016-06-27 04:26:21 UTC (rev 6412)
+++ trunk/doc/ja/html/about/history.html	2016-06-27 04:26:24 UTC (rev 6413)
@@ -42,7 +42,10 @@
   <li>\x83o\x83O\x8FC\x90\xB3
     <ul>
       <li>Windows 95/98/Me/NT4.0\x82ŋN\x93\xAE\x82ł\xAB\x82Ȃ\xAD\x82Ȃ\xC1\x82Ă\xA2\x82\xBD\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
-      <li><a href="../macro/command/strreplace.html">strreplace</a> \x83}\x83N\x83\x8D\x83R\x83}\x83\x93\x83h\x82ŁA\x90\xB3\x82\xB5\x82\xAD\x82Ȃ\xA2\x90\xB3\x8BK\x95\\x8C\xBB\x82\xF0\x8Ew\x92肵\x82\xBD\x8E\x9E\x82Ɍ\xB3\x95\xB6\x8E\x9A\x97񂪉\xF3\x82\xEA\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
+      <li><a href="../macro/command/strreplace.html">strreplace</a> \x83}\x83N\x83\x8D\x83R\x83}\x83\x93\x83h\x82ŁA\x90\xB3\x82\xB5\x82\xAD\x82Ȃ\xA2\x90\xB3\x8BK\x95\\x8C\xBB\x82\xF0\x8Ew\x92肵\x82\xBD\x8E\x9E\x82Ɍ\xB3\x95\xB6\x8E\x9A\x97񂪉\xF3\x82\xEA\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B
+        <ul>
+          <li>\x90\xB3\x82\xB5\x82\xAD\x96\xB3\x82\xA2\x90\xB3\x8BK\x95\\x8C\xBB\x82\xF0\x8Ew\x92肵\x82\xBD\x8E\x9E\x82\xCD result \x82\xC5 -1 \x82\xF0\x95Ԃ\xB7\x82悤\x82ɂ\xB5\x82\xBD\x81B</li>
+        </ul></li>
     </ul>
   </li>
 

Modified: trunk/doc/ja/html/macro/command/strreplace.html
===================================================================
--- trunk/doc/ja/html/macro/command/strreplace.html	2016-06-27 04:26:21 UTC (rev 6412)
+++ trunk/doc/ja/html/macro/command/strreplace.html	2016-06-27 04:26:24 UTC (rev 6413)
@@ -31,8 +31,9 @@
 </p>
 
 <p>
-\x92u\x8A\xB7\x82\xAA\x90\xAC\x8C\x{1C2DC2}\xE9\x82ƁA\x83V\x83X\x83e\x83\x80\x95ϐ\x94 result \x82\xC9"1"\x82\xAA\x93\xFC\x82\xE8\x81A\x90\xB3\x8BK\x95\\x8C\xBB &lt;regex&gt; \x82Ń}\x83b\x83`\x82\xB5\x82\xBD\x95\xB6\x8E\x9A\x97\xF1\x82̓V\x83X\x83e\x83\x80\x95ϐ\x94 matchstr \x82Ɋi\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
-\x92u\x8A\xB7\x82\xAA\x8E\xB8\x94s\x82\xB5\x82\xBD\x8Fꍇ\x82́Aresult \x82\xAA"0"\x82ɂȂ\xE9\x81B<br>
+\x92u\x8A\xB7\x82\xAA\x90\xAC\x8C\x{1C2DC2}\xE9\x82ƁA\x83V\x83X\x83e\x83\x80\x95ϐ\x94 result \x82\xC9 "1" \x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x81A\x90\xB3\x8BK\x95\\x8C\xBB &lt;regex&gt; \x82Ń}\x83b\x83`\x82\xB5\x82\xBD\x95\xB6\x8E\x9A\x97\xF1\x82̓V\x83X\x83e\x83\x80\x95ϐ\x94 matchstr \x82Ɋi\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+&lt;regex&gt; \x82\xAA &lt;strvar&gt; \x82̓\xE0\x97e\x82Ƀ}\x83b\x83`\x82\xB9\x82\xB8\x92u\x8A\xB7\x82\xAA\x8Ds\x82\xED\x82\xEA\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x82́Aresult \x82\xC9 "0" \x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+&lt;regex&gt; \x82̏\x91\x8E\xAE\x82\xAA\x90\xB3\x82\xB5\x82\xAD\x82Ȃ\xA2\x93\x99\x82ŃG\x83\x89\x81[\x82ƂȂ\xC1\x82\xBD\x8Fꍇ\x82́Aresult \x82\xC9 "-1" \x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B
 </p>
 
 <p>

Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2016-06-27 04:26:21 UTC (rev 6412)
+++ trunk/teraterm/ttpmacro/ttl.c	2016-06-27 04:26:24 UTC (rev 6413)
@@ -5014,11 +5014,16 @@
 	ret = FindRegexStringOne(oldstr, oldlen, p, strlen(p));
 	// FindRegexStringOne\x82̒\x86\x82\xC5UnlockVar()\x82\xB3\x82\xEA\x82Ă\xB5\x82܂\xA4\x82̂ŁALockVar()\x82\xB5\x82Ȃ\xA8\x82\xB7\x81B
 	LockVar();
-	if (ret <= 0) {
+	if (ret == 0) {
 		// \x8C\xA9\x82‚\xA9\x82\xE7\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x82́A"0"\x82Ŗ߂\xE9\x81B
 		result = 0;
 		goto error;
 	}
+	else if (ret < 0) {
+		// \x90\xB3\x82\xB5\x82\xAD\x82Ȃ\xA2\x90\xB3\x8BK\x95\\x8C\xBB\x93\x99\x82ŃG\x83\x89\x81[\x82̏ꍇ\x82\xCD -1 \x82\xF0\x95Ԃ\xB7
+		result = -1;
+		goto error;
+	}
 	ret--;
 
 	if (CheckVar("matchstr",&VarType,&VarId) &&

Added: trunk/tests/#36405-strreplace.ttl
===================================================================
--- trunk/tests/#36405-strreplace.ttl	                        (rev 0)
+++ trunk/tests/#36405-strreplace.ttl	2016-06-27 04:26:24 UTC (rev 6413)
@@ -0,0 +1,62 @@
+error_count = 0
+
+orgstr = "1234[test]1234"
+str = orgstr
+
+; "[" \x82͐\xB3\x8BK\x95\\x8C\xBB\x82Ƃ\xB5\x82Đ\xB3\x82\xB5\x82\xAD\x82Ȃ\xA2\x82̂ŃG\x83\x89\x81[\x82ƂȂ\xE9\x82ׂ\xAB
+strreplace str 1 "[" "("
+repl_result = result
+
+strcompare str orgstr
+compare_result = result
+
+if repl_result == 1 then
+	; \x92u\x8A\xB7\x90\xAC\x8C\xF7 -- \x90\xB3\x82\xB5\x82\xAD\x82Ȃ\xA2\x93\xAE\x8D\xEC
+	error_count = error_count + 1
+	msg =  "\x83G\x83\x89\x81[\x82ƂȂ\xE9\x82ׂ\xAB\x8C\x9F\x8D\xF5\x8F\xF0\x8C\x8F\x82ŃG\x83\x89\x81[\x82ɂȂ\xE8\x82܂\xB9\x82\xF1\x82ł\xB5\x82\xBD"
+	if compare_result <> 0 then
+		; \x95\xB6\x8E\x9A\x97񂪉󂳂ꂽ
+		error_count = error_count + 1
+		strconcat msg #13#10"\x8C\xB3\x95\xB6\x8E\x9A\x97\xF1\x82\xE0\x89\xF3\x82\xEA\x82Ă\xA2\x82܂\xB7"
+	endif
+	messagebox msg "\x83G\x83\x89\x81["
+
+elseif repl_result == 0 then
+	; not found (\x8Eb\x92\xE8\x8FC\x90\xB3\x8E\x9E\x82̓\xAE\x8D\xEC)
+	error_count = error_count + 1
+	msg = "\x8C\x9F\x8D\x{14C2C9}ʂ\xAA not found \x82ƂȂ\xE8\x82܂\xB5\x82\xBD"
+	if compare_result <> 0 then
+		; \x95\xB6\x8E\x9A\x97񂪉󂳂ꂽ
+		error_count = error_count + 1
+		strconcat msg #13#10"\x8C\xB3\x95\xB6\x8E\x9A\x97\xF1\x82\xE0\x89\xF3\x82\xEA\x82Ă\xA2\x82܂\xB7"
+	endif
+	messagebox msg "\x83G\x83\x89\x81["
+
+elseif repl_result == -1 then
+	; strreplace \x82\xAA\x83G\x83\x89\x81[\x82ƂȂ\xC1\x82\xBD -- \x90\xB3\x82\xB5\x82\xA2\x93\xAE\x8D\xEC
+	if compare_result <> 0 then
+		; \x95\xB6\x8E\x9A\x97񂪉󂳂ꂽ
+		error_count = error_count + 1
+		messagebox "\x95\xB6\x8E\x9A\x97񂪉\xF3\x82\xEA\x82Ă\xA2\x82܂\xB7" "\x83G\x83\x89\x81["
+	endif
+else
+	; strreplace \x82\xCC result \x82\xAA\x88ُ\xED
+	error_count = error_count + 1
+	sprintf2 msg "strreplace\x82̕Ԃ\xE8\x92l\x82\xAA\x88ُ\xED\x82ł\xB7(%d)" repl_result
+	if compare_result <> 0 then
+		; \x95\xB6\x8E\x9A\x97񂪉󂳂ꂽ
+		error_count = error_count + 1
+		strconcat msg #13#10"\x8C\xB3\x95\xB6\x8E\x9A\x97\xF1\x82\xE0\x89\xF3\x82\xEA\x82Ă\xA2\x82܂\xB7"
+	endif
+	messagebox msg "\x83G\x83\x89\x81["
+endif
+
+if error_count == 0 then
+	messagebox "\x90\xB3\x8F\xED\x8FI\x97\xB9" "\x8C\x8B\x89\xCA"
+else
+	sprintf2 msg "%d \x8C\x8F\x82̃G\x83\x89\x81[\x82\xAA\x94\xAD\x90\xB6\x82\xB5\x82܂\xB5\x82\xBD" error_count
+	messagebox msg "\x8C\x8B\x89\xCA"
+	setexitcode 1
+endif
+
+end



Ttssh2-commit メーリングリストの案内