diff options
author | Vincent Fiduccia <vincent@rancher.com> | 2019-06-02 09:56:19 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-06-02 11:23:48 +0300 |
commit | 35abce27cabee43cc751db55a75b927f26275833 (patch) | |
tree | b4113a6cc1423f164cab4d5619dbf17224835f47 /resources/resource_factories | |
parent | 8914fe7ed7e7e55e07be32564159310c90e2dbd4 (diff) |
Add safety barrier between concatenated javascript resources
Diffstat (limited to 'resources/resource_factories')
-rw-r--r-- | resources/resource_factories/bundler/bundler.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/resources/resource_factories/bundler/bundler.go b/resources/resource_factories/bundler/bundler.go index ca0ccf86e..59810e347 100644 --- a/resources/resource_factories/bundler/bundler.go +++ b/resources/resource_factories/bundler/bundler.go @@ -15,6 +15,7 @@ package bundler import ( + "bytes" "fmt" "io" "path/filepath" @@ -92,12 +93,30 @@ func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resou } return nil, err } + rcsources = append(rcsources, rc) } - readers := make([]io.Reader, len(rcsources)) - for i := 0; i < len(rcsources); i++ { - readers[i] = rcsources[i] + var readers []io.Reader + + // Arbitrary JavaScript files require a barrier between them to be safely concatenated together. + // Without this, the last line of one file can affect the first line of the next file and change how both files are interpreted. + if resolvedm.MainType == media.JavascriptType.MainType && resolvedm.SubType == media.JavascriptType.SubType { + readers = make([]io.Reader, 2*len(rcsources)-1) + j := 0 + for i := 0; i < len(rcsources); i++ { + if i > 0 { + readers[j] = bytes.NewBufferString("\n;\n") + j++ + } + readers[j] = rcsources[i] + j++ + } + } else { + readers = make([]io.Reader, len(rcsources)) + for i := 0; i < len(rcsources); i++ { + readers[i] = rcsources[i] + } } mr := io.MultiReader(readers...) |