The Inbox: Collections-ct.945.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-ct.945.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.945.mcz

==================== Summary ====================

Name: Collections-ct.945
Author: ct
Time: 6 May 2021, 10:08:28.643835 pm
UUID: 4a526dd8-6418-c44f-aa41-3de63a54b393
Ancestors: Collections-mt.943

Makes HtmlReadWriter robust against HTML5 void tags. As opposed to XHTML tags, they need to be closed manually.

In the past, HTML strings such as the following failed with an "error: this stack is empty":

        '<img src="code://Form fromDisplay: World bounds"></img>' asTextFromHtml

This problem is now solved by ignoring void tags in #processEndTag:.

=============== Diff against Collections-mt.943 ===============

Item was added:
+ ----- Method: HtmlReadWriter>>isVoidTag: (in category 'testing') -----
+ isVoidTag: aTag
+
+ ^ self voidTags includes: aTag!

Item was changed:
  ----- Method: HtmlReadWriter>>processEndTag: (in category 'reading') -----
  processEndTag: aTag
 
  | index tagName |
  index := count - offset.
  tagName := aTag copyFrom: 3 to: aTag size - 1.
+
-
  (self isTagIgnored: tagName) ifTrue: [^ self].
+ (self isVoidTag: tagName) ifTrue: [^ self].
 
  tagName = 'code' ifTrue: [self mapCloseCodeTag].
  tagName = 'pre' ifTrue: [self breakLines: true].
+
-
  self processRunStackTop.
+
-
  runStack pop.
+ runStack top at: 2 put: index + 1!
- runStack top at: 2 put: index + 1.!

Item was removed:
- ----- Method: HtmlReadWriter>>processEndTagEagerly: (in category 'reading') -----
- processEndTagEagerly: aTag
- "Not all tags need an end tag. Simulate that here."
-
- (aTag beginsWith: '<img')
- ifTrue: [^ self processEndTag: '</img>'].!

Item was changed:
  ----- Method: HtmlReadWriter>>processStartTag: (in category 'reading') -----
  processStartTag: aTag
 
+ | tagName index |
+ tagName := (aTag copyWithoutAll: '</>') copyUpTo: Character space.
+ (self isTagIgnored: tagName) ifTrue: [^ self].
+
- | index |
- (self isTagIgnored: aTag) ifTrue: [^ self].
-
  index := count - offset.
+
+ tagName = 'br' ifTrue: [
-
- aTag = '<br>' ifTrue: [
  self addCharacter: Character cr.
  ^ self].
+
+ tagName = 'img' ifTrue: [
-
- (aTag beginsWith: '<img') ifTrue: [
  self addString: Character startOfHeader asString.
  offset := offset + 1.
  index := index - 1].
 
+ self processRunStackTop.
+ "To add all attributes before the next tag adds some."
- self processRunStackTop. "To add all attributes before the next tag adds some."
-
  "Copy attr list and add new attr."
+ runStack push: {
+ runStack top first copy
+ addAll: (self mapTagToAttribute: aTag);
+ yourself.
+ index + 1.
+ index + 1}.
+
+ "For void tags such as <img>, we should simulate the closing tag because in case of HTML5 there won't be any."
+ (self isVoidTag: tagName) ifTrue: [self processEndTag: tagName]!
- runStack push: ({runStack top first copy addAll: (self mapTagToAttribute: aTag); yourself. index + 1 . index + 1}).
-
- "For tags such as <img>, we should simulate the closing tag because there won't be any."
- self processEndTagEagerly: aTag.!

Item was added:
+ ----- Method: HtmlReadWriter>>voidTags (in category 'accessing') -----
+ voidTags
+ "Tags that are empty and won't be closed in HTML5."
+
+ ^ #(#img)!