Jürgen Spitzmüller wrote:

> Georg Baum wrote:
>> - char() == 0, so a string with an embedded 0 character could be created.
>> This is not what was intended.
> 
> I see. However, I remember I got some error when I tried the "" variant.

You probably tried the char version. This one needs always a replacement
char, but with the const char * version you can also use "" as replacement.

>> - fs::exists was called for a filename that was not checked with
>> fs::native, so an excpetion could be thrown.
> 
> OK. However, note that, if the string without quotation marks is no valid
> file name, I proceeded _with_ the quotation marks (because they might very
> well be part of the file name). I think your version removes them
> forwever, which is wrong.

OK, I did not notice that. What about the attached version? This is your
original one, with the missing test added.

>> BTW I don't like this test for max path length:
>>
>>
>>         if (token.length() > 255) {
>>                 // string too long. Cut off.
>>                 int r = token.length() - 250;
>>                 string ntoken = token.substr(r, token.length());
>>                 token = ntoken;
>>         }
>>
>> Nobody knows where the 255 comes from. I believe that this test is no
>> longer needed (the fs::native check should catch these cases, can anybody
>> confirm this?), but if it is, then something like this should be used:
> 
> It is needed. We need to strip of the string, else it is getting endless.

Ah, so the 255 was both for windows max path and because the string must not
grow endlessly. In that case I would prefer a suitable name for this
constant. MAX_PATH or PATH_MAX are misleading, since it implies that the
length is limited by an OS constant, but was is really used here is a more
or less arbitrary length limit rfor parsing purposes.


Georg
Index: src/LaTeX.C
===================================================================
--- src/LaTeX.C	(Revision 17452)
+++ src/LaTeX.C	(Arbeitskopie)
@@ -802,7 +802,7 @@ bool handleFoundFile(string const & ff, 
 			while (contains(strippedfile, " ")) {
 				// files with spaces are often enclosed in quotation
 				// marks; those have to be removed
-				string unquoted = subst(strippedfile, '"', char());
+				string unquoted = subst(strippedfile, "\"", "");
 				absname.set(unquoted);
 				if (insertIfExists(absname, head))
 					return true;
@@ -833,12 +833,20 @@ bool handleFoundFile(string const & ff, 
 		if (exists)
 			// everything o.k.
 			break;
-		else if (contains(foundfile, '"')) {
+		else {
 			// files with spaces are often enclosed in quotation
-			// marks; remove those and try again
+			// marks; those have to be removed
 			string unquoted = subst(foundfile, "\"", "");
 			absname = makeAbsPath(unquoted);
-		} else {
+			exists = fs::native(absname.toFilesystemEncoding());
+			if (exists)
+				exists = fs::exists(absname.toFilesystemEncoding());
+			else
+				lyxerr[Debug::DEPEND] << '`'
+					<< absname.absFilename()
+					<< "' is no valid file name." << endl;
+			if (exists)
+				break;
 			// strip off part after last space and try again
 			string strippedfile;
 			string const stripoff =
@@ -982,9 +990,7 @@ void LaTeX::deplog(DepTable & head)
 			token = lastline + token;
 		if (token.length() > 255) {
 			// string too long. Cut off.
-			int r = token.length() - 250;
-			string ntoken = token.substr(r, token.length());
-			token = ntoken;
+			token.erase(0, token.length() - 251);
 		}
 
 		smatch sub;

Reply via email to