Program: 45343
Project: 45343
Buggy source:
/** 
 * Parse an attribute value.
 * @param name attribute name
 * @param foldCase fold case?
 * @param isempty is attribute empty? Passed as an array reference to allow modification
 * @param pdelim delimiter, passed as an array reference to allow modification
 * @return parsed value
 */
public String parseValue(String name,boolean foldCase,boolean[] isempty,int[] pdelim){
  int len=0;
  int start;
  boolean seenGt=false;
  boolean munge=true;
  int c=0;
  int lastc, delim, quotewarning;
  String value;
  delim=0;
  pdelim[0]='"';
  if (this.configuration.isLiteralAttribs()) {
    munge=false;
  }
  while (true) {
    c=this.in.readChar();
    if (c == StreamIn.END_OF_STREAM) {
      this.in.ungetChar(c);
      break;
    }
    if (!TidyUtils.isWhite((char)c)) {
      break;
    }
  }
  if (c != '=' && c != '"' && c != '\'') {
    this.in.ungetChar(c);
    return null;
  }
  while (true) {
    c=this.in.readChar();
    if (c == StreamIn.END_OF_STREAM) {
      this.in.ungetChar(c);
      break;
    }
    if (!TidyUtils.isWhite((char)c)) {
      break;
    }
  }
  if (c == '"' || c == '\'') {
    delim=c;
  }
 else   if (c == '<') {
    start=this.lexsize;
    addCharToLexer(c);
    pdelim[0]=parseServerInstruction();
    len=this.lexsize - start;
    this.lexsize=start;
    return (len > 0 ? TidyUtils.getString(this.lexbuf,start,len) : null);
  }
 else {
    this.in.ungetChar(c);
  }
  quotewarning=0;
  start=this.lexsize;
  c='\0';
  while (true) {
    lastc=c;
    c=this.in.readChar();
    if (c == StreamIn.END_OF_STREAM) {
      report.attrError(this,this.token,null,Report.UNEXPECTED_END_OF_FILE);
      this.in.ungetChar(c);
      break;
    }
    if (delim == (char)0) {
      if (c == '>') {
        this.in.ungetChar(c);
        break;
      }
      if (c == '"' || c == '\'') {
        report.attrError(this,this.token,null,Report.UNEXPECTED_QUOTEMARK);
        break;
      }
      if (c == '<') {
        this.in.ungetChar(c);
        c='>';
        this.in.ungetChar(c);
        report.attrError(this,this.token,null,Report.UNEXPECTED_GT);
        break;
      }
      if (c == '/') {
        c=this.in.readChar();
        if (c == '>' && !AttributeTable.getDefaultAttributeTable().isUrl(name)) {
          isempty[0]=true;
          this.in.ungetChar(c);
          break;
        }
        this.in.ungetChar(c);
        c='/';
      }
    }
 else {
      if (c == delim) {
        break;
      }
      if (c == '\r') {
        c=this.in.readChar();
        if (c != '\n') {
          this.in.ungetChar(c);
        }
        c='\n';
      }
      if (c == '\n' || c == '<' || c == '>') {
        ++quotewarning;
      }
      if (c == '>') {
        seenGt=true;
      }
    }
    if (c == '&') {
      if ("String_Node_Str".equalsIgnoreCase(name)) {
        report.attrError(this,null,null,Report.ENTITY_IN_ID);
        continue;
      }
      addCharToLexer(c);
      parseEntity((short)0);
      continue;
    }
    if (c == '\\') {
      c=this.in.readChar();
      if (c != '\n') {
        this.in.ungetChar(c);
        c='\\';
      }
    }
    if (TidyUtils.isWhite((char)c)) {
      if (delim == (char)0) {
        break;
      }
      if (munge) {
        if (c == '\n' && AttributeTable.getDefaultAttributeTable().isUrl(name)) {
          report.attrError(this,this.token,null,Report.NEWLINE_IN_URI);
          continue;
        }
        c=' ';
        if (lastc == ' ') {
          continue;
        }
      }
    }
 else     if (foldCase && TidyUtils.isUpper((char)c)) {
      c=TidyUtils.toLower((char)c);
    }
    addCharToLexer(c);
  }
  if (quotewarning > 10 && seenGt && munge) {
    if (!AttributeTable.getDefaultAttributeTable().isScript(name) && !(AttributeTable.getDefaultAttributeTable().isUrl(name) && "String_Node_Str".equals(TidyUtils.getString(this.lexbuf,start,11))) && !"String_Node_Str".equals(TidyUtils.getString(this.lexbuf,start,5))) {
      report.error(this,null,null,Report.SUSPECTED_MISSING_QUOTE);
    }
  }
  len=this.lexsize - start;
  this.lexsize=start;
  if (len > 0 || delim != 0) {
    if (munge && !TidyUtils.isInValuesIgnoreCase(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},name)) {
      while (TidyUtils.isWhite((char)this.lexbuf[start + len - 1])) {
        --len;
      }
      while (TidyUtils.isWhite((char)this.lexbuf[start]) && start < len) {
        ++start;
        --len;
      }
    }
    value=TidyUtils.getString(this.lexbuf,start,len);
  }
 else {
    value=null;
  }
  if (delim != 0) {
    pdelim[0]=delim;
  }
 else {
    pdelim[0]='"';
  }
  return value;
}

Fixed version (ground truth):
/** 
 * Parse an attribute value.
 * @param name attribute name
 * @param foldCase fold case?
 * @param isempty is attribute empty? Passed as an array reference to allow modification
 * @param pdelim delimiter, passed as an array reference to allow modification
 * @return parsed value
 */
public String parseValue(String name,boolean foldCase,boolean[] isempty,int[] pdelim){
  int len=0;
  int start;
  boolean seenGt=false;
  boolean munge=true;
  int c=0;
  int lastc, delim, quotewarning;
  String value;
  delim=0;
  pdelim[0]='"';
  if (this.configuration.isLiteralAttribs()) {
    munge=false;
  }
  while (true) {
    c=this.in.readChar();
    if (c == StreamIn.END_OF_STREAM) {
      this.in.ungetChar(c);
      break;
    }
    if (!TidyUtils.isWhite((char)c)) {
      break;
    }
  }
  if (c != '=' && c != '"' && c != '\'') {
    this.in.ungetChar(c);
    return null;
  }
  while (true) {
    c=this.in.readChar();
    if (c == StreamIn.END_OF_STREAM) {
      this.in.ungetChar(c);
      break;
    }
    if (!TidyUtils.isWhite((char)c)) {
      break;
    }
  }
  if (c == '"' || c == '\'') {
    delim=c;
  }
 else   if (c == '<') {
    start=this.lexsize;
    addCharToLexer(c);
    pdelim[0]=parseServerInstruction();
    len=this.lexsize - start;
    this.lexsize=start;
    return (len > 0 ? TidyUtils.getString(this.lexbuf,start,len) : null);
  }
 else {
    this.in.ungetChar(c);
  }
  quotewarning=0;
  start=this.lexsize;
  c='\0';
  while (true) {
    lastc=c;
    c=this.in.readChar();
    if (c == StreamIn.END_OF_STREAM) {
      report.attrError(this,this.token,null,Report.UNEXPECTED_END_OF_FILE);
      this.in.ungetChar(c);
      break;
    }
    if (delim == (char)0) {
      if (c == '>') {
        this.in.ungetChar(c);
        break;
      }
      if (c == '"' || c == '\'') {
        int q=c;
        report.attrError(this,this.token,null,Report.UNEXPECTED_QUOTEMARK);
        c=in.readChar();
        if (c == '>') {
          addCharToLexer(q);
          in.ungetChar(c);
          break;
        }
 else {
          in.ungetChar(c);
          c=q;
        }
      }
      if (c == '<') {
        this.in.ungetChar(c);
        c='>';
        this.in.ungetChar(c);
        report.attrError(this,this.token,null,Report.UNEXPECTED_GT);
        break;
      }
      if (c == '/') {
        c=this.in.readChar();
        if (c == '>' && !AttributeTable.getDefaultAttributeTable().isUrl(name)) {
          isempty[0]=true;
          this.in.ungetChar(c);
          break;
        }
        this.in.ungetChar(c);
        c='/';
      }
    }
 else {
      if (c == delim) {
        break;
      }
      if (c == '\r') {
        c=this.in.readChar();
        if (c != '\n') {
          this.in.ungetChar(c);
        }
        c='\n';
      }
      if (c == '\n' || c == '<' || c == '>') {
        ++quotewarning;
      }
      if (c == '>') {
        seenGt=true;
      }
    }
    if (c == '&') {
      if ("String_Node_Str".equalsIgnoreCase(name)) {
        report.attrError(this,null,null,Report.ENTITY_IN_ID);
        continue;
      }
      addCharToLexer(c);
      parseEntity((short)0);
      continue;
    }
    if (c == '\\') {
      c=this.in.readChar();
      if (c != '\n') {
        this.in.ungetChar(c);
        c='\\';
      }
    }
    if (TidyUtils.isWhite((char)c)) {
      if (delim == (char)0) {
        break;
      }
      if (munge) {
        if (c == '\n' && AttributeTable.getDefaultAttributeTable().isUrl(name)) {
          report.attrError(this,this.token,null,Report.NEWLINE_IN_URI);
          continue;
        }
        c=' ';
        if (lastc == ' ') {
          continue;
        }
      }
    }
 else     if (foldCase && TidyUtils.isUpper((char)c)) {
      c=TidyUtils.toLower((char)c);
    }
    addCharToLexer(c);
  }
  if (quotewarning > 10 && seenGt && munge) {
    if (!AttributeTable.getDefaultAttributeTable().isScript(name) && !(AttributeTable.getDefaultAttributeTable().isUrl(name) && "String_Node_Str".equals(TidyUtils.getString(this.lexbuf,start,11))) && !"String_Node_Str".equals(TidyUtils.getString(this.lexbuf,start,5))) {
      report.error(this,null,null,Report.SUSPECTED_MISSING_QUOTE);
    }
  }
  len=this.lexsize - start;
  this.lexsize=start;
  if (len > 0 || delim != 0) {
    if (munge && !TidyUtils.isInValuesIgnoreCase(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},name)) {
      while (TidyUtils.isWhite((char)this.lexbuf[start + len - 1])) {
        --len;
      }
      while (TidyUtils.isWhite((char)this.lexbuf[start]) && start < len) {
        ++start;
        --len;
      }
    }
    value=TidyUtils.getString(this.lexbuf,start,len);
  }
 else {
    value=null;
  }
  if (delim != 0) {
    pdelim[0]=delim;
  }
 else {
    pdelim[0]='"';
  }
  return value;
}