# GitHub onebox does not skip leading tabs

**URL:** <https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891>\
**Category:** Feature\
**Created:** [April 20, 2016, 4:16pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891 "2016-04-20T16:16:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmitry\_fedyuk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dmitry_fedyuk/32/293153_2.png) [@dmitry\_fedyuk](https://meta.discourse.org/u/dmitry_fedyuk)\
**Post date:** [April 20, 2016, 4:16pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891/1 "2016-04-20T16:16:39Z")

</div>

## An incorrect rendering (the code uses tabs):

> <https://github.com/mage2pro/core/blob/6f01886/Checkout/view/frontend/web/js/data.js?ts=4#L46-L48>

## A correct rendering (the code uses spaces):

> <https://github.com/magento/magento2/blob/072a1ae/app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js#L121-L124>

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [April 20, 2016, 4:24pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891/2 "2016-04-20T16:24:29Z")

</div>

I don’t understand why this is a bug. The file contains tabs… so it is displaying tabs. Discourse isn’t adding any additional tabs, it is still displaying 4 of them.

Are you saying the onebox should replace tabs with spaces? As why should a onebox alter content of the file it is referencing?

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [April 20, 2016, 5:47pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891/3 "2016-04-20T17:47:48Z")

</div>

The [Github onebox strips leading spaces](https://github.com/discourse/onebox/blob/master/lib/onebox/engine/github_blob_onebox.rb#L105-L131), but not tabs.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [April 20, 2016, 5:51pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891/4 "2016-04-20T17:51:02Z")

</div>

If that’s the case then we might extend this to tabs as well for consistency so @dmitry_fedyuk has a point.

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [April 20, 2016, 5:51pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891/5 "2016-04-20T17:51:27Z")

</div>

Ah, so that seems to be as simple as changing (and its other usage `^[]{#{min_space}}`)  
`^[]*`

to  
`^[\s]*`

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [April 20, 2016, 6:15pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891/6 "2016-04-20T18:15:58Z")

</div>

> <https://github.com/discourse/onebox/blob/main/lib/onebox/engine/github_blob_onebox.rb#L112-L127>

There are two lines these change would need to be made on:

```ruby
  m = l.match /^[]*/ # find leading spaces 0 or more

```

and

```ruby
  re = Regexp.new "^[]{#{min_space}}" #match the minimum spaces of the line

```

Please be specific about white spacing (i.e. use `[\t]`), using `\s` may cause unicode white-space ghosts past, present and future to come back and kick your ass.

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [April 20, 2016, 8:50pm UTC](https://meta.discourse.org/t/github-onebox-does-not-skip-leading-tabs/42891/7 "2016-04-20T20:50:50Z")

</div>

Actually, I don’t think that is a concern, if Ruby’s regex uses PCRE, it only matches a subset of values unless it is specifically compiled in a way that can put a strain on performance using the PCRE\_UCP option.  
[http://www.pcre.org/pcre.txt](http://www.pcre.org/pcre.txt)

Plus that non-whitespace would have to be at the start of a line, which is unlikely too, granted, I guess someone could write a literal string across multiple lines.

Fairly certain `\s` is safe, but I also have nothing against specifying `\t`. Another approach would be to replace all instances of `\t` at the beginning of a line with 4 spaces and let the logic continue on its way since it already works with spaces.

So I’d say there is a very very small chance that `\s` would be problematic. Especially given that it would have to be a multi-line literal string. Otherwise, there would be zero chance of it the line starting with a unicode whitespace.
