View | Details | Raw Unified | Return to bug 200389 | Differences between
and this patch

Collapse All | Expand All

(-)Link.java (-4 / +115 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2002-2006 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2002-2007 Innoopract Informationssysteme GmbH and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 *     Mariot Chauvin <mariot.chauvin@gmail.com> - bug 200389
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.swt.widgets;
13
package org.eclipse.swt.widgets;
Lines 104-115 Link Here
104
    if( string == null ) {
105
    if( string == null ) {
105
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
106
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
106
    }
107
    }
107
    if( !string.equals( text ) ) {
108
    
108
      displayText = parse( string );
109
    String escaped_input =escape_html(string);
109
      text = string;
110
    
111
    if( !escaped_input.equals( text ) ) {
112
      displayText = parse( escaped_input );
113
      text = escaped_input;
110
    }
114
    }
111
  }
115
  }
112
116
117
  
118
  private String escape_html(String input) {
119
	  
120
	  StringBuffer escaped_input = new StringBuffer(input.length());
121
	  
122
	  int state = 0;
123
	  
124
	  //copy inpout String into a tab of chars 
125
	  char input_chars[] = new char[input.length()];
126
	  input.getChars(0, input.length(), input_chars, 0);
127
	
128
	  for (int i=0; i<input_chars.length ; i++) {
129
130
		  switch(state)
131
		  {
132
		  
133
		  case 0 :
134
			  if (input_chars[i]=='<') {
135
				  state = 1;
136
			  } else {
137
				  escaped_input.append(input_chars[i]);
138
			  }
139
			  break;
140
		 
141
		  case 1 :
142
			  if (input_chars[i]=='a') {
143
				  state = 2;
144
			  } else if (input_chars[i]=='/'){
145
				  state = 3;
146
			  } else {
147
				  escaped_input.append("&lt;");
148
				  escaped_input.append(input_chars[i]);
149
				  state = 5;
150
			  }
151
			  break;
152
153
		  case 2 :
154
			  if (input_chars[i]=='>'  || input_chars[i]=='>') {
155
				  escaped_input.append('<');
156
				  state = 0;
157
			  } else {
158
				  escaped_input.append("&lt;");
159
				  state = 5;
160
			  }
161
			  escaped_input.append('a');
162
			  escaped_input.append(input_chars[i]);
163
			  break;
164
165
			  
166
		  case 3 :
167
			  if (input_chars[i]=='a') {
168
				  state = 4;
169
			  } else {
170
				  escaped_input.append("&lt;/");
171
				  escaped_input.append(input_chars[i]);
172
				  state = 5;
173
			  }
174
			  break;  
175
			
176
		  case 4 :
177
			  if (input_chars[i]=='>') {
178
				  escaped_input.append('<');
179
				  state = 0;
180
			  } else {
181
				  escaped_input.append("&lt;");
182
				  state = 5;
183
			  }
184
			  escaped_input.append("/a");
185
			  escaped_input.append(input_chars[i]);
186
			  break;
187
			  
188
		  case 5 :
189
			  if (input_chars[i]=='<') {
190
				  escaped_input.append("&lt;");
191
			  } else if (input_chars[i]=='>') {
192
				  escaped_input.append("&gt;");
193
				  state = 0;
194
			  } else {
195
				  escaped_input.append(input_chars[i]);
196
			  }
197
			  break;
198
		  }
199
	  }
200
	 
201
	  switch(state) {
202
	  	case 0:
203
	  		break;
204
	  	case 1:
205
	  		 escaped_input.append("&lt;");
206
	  		break;
207
	  	case 2:
208
	  		escaped_input.append("&lt;a");
209
	  		break;
210
	  	case 3:
211
	  		escaped_input.append("&lt;/");
212
	  		break;
213
	  	case 4:
214
	  		escaped_input.append("&lt;/a");
215
	  		break;
216
	  	case 5:
217
	  		break;
218
	  }
219
	  
220
	  return escaped_input.toString();
221
  }
222
  
223
  
113
  /**
224
  /**
114
   * Returns the receiver's text, which will be an empty
225
   * Returns the receiver's text, which will be an empty
115
   * string if it has never been set.
226
   * string if it has never been set.

Return to bug 200389