Branch: Tag:

2010-10-10

2010-10-10 21:56:30 by Martin Stjernholm <mast@lysator.liu.se>

Corrected handling of NULs in split_quoted_string.

395:    for(int e=1;e<sizeof(x);e++)    {    string piece = x[e]; -  if (!sizeof(piece)) { -  // Escaped NUL. -  last += "\0"; -  e++; +  if (piece == "") { +  // Escaped NUL. There should always be another element in x. +  last += "\0" + x[++e];    continue;    }    switch(piece[0])    {    case '"': -  +  always_keep_last = 1;    last+=piece[1..]; -  while(sizeof (x) > e + 1 && (piece = x[++e])[0]!='"') -  { -  if(sizeof(piece)==1 && piece[0]=='\\' && x[e+1][0]=='"') +  while (1) { +  if (++e == sizeof (x)) +  break piece_loop; +  if (has_prefix (piece = x[e], "\"")) +  break; +  if (piece == "") { // Escaped NUL. +  last += "\0" + x[++e]; +  } +  else { +  if(piece == "\\" && sizeof (x) > e + 1 && has_prefix (x[e+1], "\""))    piece = x[++e];    last+=piece;    } -  +  }    last+=piece[1..]; -  always_keep_last = 1; +     break;       case '\'': -  +  always_keep_last = 1;    last+=piece[1..]; -  while(sizeof (x) > e + 1 && (piece = x[++e])[0]!='\'') last+=piece; +  while (1) { +  if (++e == sizeof (x)) +  break piece_loop; +  if (has_prefix (piece = x[e], "'")) +  break; +  if (piece == "") { // Escaped NUL. +  last += "\0" + x[++e]; +  } +  else +  last+=piece; +  }    last+=piece[1..]; -  always_keep_last = 1; +     break;       case '\\':
458:    ret += ({last});    last = piece[1..];    break; -  -  default: -  last+="\0"+piece; -  break; +     }    }    if (sizeof (last) || always_keep_last)