Skip to content

Commit

Permalink
Merge pull request #1 from pallxk/master
Browse files Browse the repository at this point in the history
Get rows under table using find instead of children
  • Loading branch information
ViliusSutkus89 authored Jul 4, 2021
2 parents 251a507 + eae384d commit 1db4729
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = src => {
const dir = '/' + $('h1').text().split('/').slice(1).join('/');
const files = [];

const rows = $('table').children('tr').toArray();
const rows = $('table').find('tr').toArray();

// Figure out the order of the columns,
// by looking at the header row.
Expand Down
62 changes: 62 additions & 0 deletions test/fixture/apache-index-doc-outerhtml.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<html><head>
<title>Index of /foo/bar</title>
</head>
<body>
<h1>Index of /foo/bar</h1>


<table>
<tbody><tr>
<th><img src="/icons/blank.gif" alt="[ICO]"></th>
<th><a href="?C=N;O=D">Name</a></th>
<th><a href="?C=M;O=A">Last modified</a></th>
<th><a href="?C=S;O=A">Size</a></th>
<th><a href="?C=D;O=A">Description</a></th>
</tr>
<tr>
<th colspan="5">
<hr>
</th>
</tr>
<tr>
<td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>
<td><a href="/foo">Parent Directory</a></td>
<td>&nbsp;</td>
<td align="right"> -</td>
<td>&nbsp;</td>
</tr>


<tr>
<td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>
<td><a href="folderA/">folderA/</a></td>
<td align="right">25-May-2016 11:53</td>
<td align="right"></td>
<td>The very first folder</td>
</tr>
<tr>
<td valign="top"><img src="/icons/folder.gif" alt="[]"></td>
<td><a href="folderB/">folderB/</a></td>
<td align="right">19-May-2016 17:57</td>
<td align="right"> 5.4M</td>
<td>&nbsp;</td>
</tr>
<tr>
<td valign="top"><img src="/icons/compressed.gif" alt="[ ]"></td>
<td><a href="fileA.zip">fileA.zip</a></td>
<td align="right">28-May-2009 15:09</td>
<td align="right"> 56K</td>
<td>&nbsp;</td>
</tr>
<tr>
<td valign="top"><img src="/icons/compressed.gif" alt="[ ]"></td>
<td><a href="fileB.zip">fileB.zip</a></td>
<td align="right">28-May-2009 17:32</td>
<td align="right">647K</td>
<td>&nbsp;</td>
</tr>

</tbody></table>


</body></html>
43 changes: 43 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,49 @@ test('should parse apache directory index files', t => {
t.end();
});

test('should parse apache directory index files generated by `document.documentElement.outerHTML`', t => {
const index = fs.readFileSync(`${__dirname}/fixture/apache-index-doc-outerhtml.html`, 'utf8');

t.deepEqual(parse(index), {
dir: '/foo/bar',
files: [
{
name: 'folderA/',
type: 'directory',
path: '/foo/bar/folderA/',
description: 'The very first folder',
size: null,
lastModified: new Date('25-May-2016 11:53')
},
{
name: 'folderB/',
type: 'directory',
path: '/foo/bar/folderB/',
size: 5662310.4,
lastModified: new Date('19-May-2016 17:57'),
description: ''
},
{
name: 'fileA.zip',
type: 'file',
path: '/foo/bar/fileA.zip',
size: 57344,
lastModified: new Date('28-May-2009 15:09'),
description: ''
},
{
name: 'fileB.zip',
type: 'file',
path: '/foo/bar/fileB.zip',
size: 662528,
lastModified: new Date('28-May-2009 17:32'),
description: ''
}
]
});
t.end();
});

test('should parse apache directory index files (alt format)', t => {
const index = fs.readFileSync(`${__dirname}/fixture/apache-index-alt.html`, 'utf8');

Expand Down

0 comments on commit 1db4729

Please sign in to comment.